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 ...