thinkphp3.x How to connect MySQL database (procedure), thinkphp3.xmysql_php tutorial

Source: Internet
Author: User
Tags php template smarty template

thinkphp3.x How to connect MySQL database (procedure), Thinkphp3.xmysql


This paper describes the method of thinkphp3.x connection to MySQL database. Share to everyone for your reference, as follows:

Formula Profile: thinkphp/conf/convention.php

(1) Fill in the configuration information (configuration file: "./xmall/conf/config.php") in the configuration file:

Example:

<?phpreturn Array (   //' config item ' = = ' config value '/   * * Database Settings */    ' db_type '    = ' mysql ',  //database type    ' Db_ HOST '    = = ' localhost ',//server address    ' db_name '    = ' xmall ',  //Database name    ' db_user ' +    ' root ' ,//  username    ' db_pwd '    = ' 123 ',//password    ' db_port '    = ' 3306 ',  //Port    ' Db_prefix '    = ' think_ ',//database table prefix    ' db_fieldtype_check ' = False,  //whether field type check    ' Db_fields_cache '  = = True,  //enable field cache    ' db_charset '   = ' utf8 ',  //Database encoding defaults to UTF8); >

(2) Create a table:

CREATE TABLE ' think_user ' (  ' id ' int (one) default null,  ' name ' varchar () default NULL,  ' pwd ' varchar (DEF) Ault NULL) Engine=innodb;

(3) Perform data insert operation modify the IndexAction.class.php file under Lib/action, as follows:

<?phpclass indexaction extends action{   function index () {Public     function index () {       $data =array (          " ID "+" 1 ",          " name= "=" liuning ",         " pwd "=" asd123 "       );       M ("User")->add ($data);}}   ? >

(4) Implementation of http://localhost/xmall/index.php, the database will have a new record generation;

PS: Here are recommended several of the format of the site landscaping tools, I believe that we can use in the future development:

PHP Code online format Beautification tool:
Http://tools.jb51.net/code/phpformat

JavaScript code beautification/compression/formatting/encryption Tools:
Http://tools.jb51.net/code/jscompress

Online XML format/compression tool:
Http://tools.jb51.net/code/xmlformat

JSON Code formatting beautification tool:
Http://tools.jb51.net/code/json

Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson

SQL code online Format beautification tool:
Http://tools.jb51.net/code/sqlcodeformat

More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Common Methods Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."

It is hoped that this article is helpful to the PHP program design based on thinkphp framework.

http://www.bkjia.com/PHPjc/1127839.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127839.html techarticle thinkphp3.x Connection MySQL database method (specific steps), Thinkphp3.xmysql This article describes the thinkphp3.x connection MySQL database method. Share to everyone for your reference, specific ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.