Thinkphp3.x connection to the mysql database (specific operation steps), thinkphp3.xmysql. Thinkphp3.x connection to the mysql database (specific operation steps), thinkphp3.xmysql this article describes how thinkphp3.x connects to the mysql database. For your reference, the thinkphp3.x connection method to the mysql database (specific operation steps) and thinkphp3.xmysql
This article describes how thinkphp3.x connects to the mysql database. We will share this with you for your reference. The details are as follows:
Convention configuration file: ThinkPHP/conf/convention. php
(1) fill in the configuration information in the configuration file (configuration file: "./xmall/conf/config. php "):
Example:
<? Phpreturn array (// 'config map '=> 'configuration 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' => '123', // PORT 'DB _ prefix' => 'think _', // database table prefix 'DB _ FIELDTYPE_CHECK '=> false, // check whether the field type is checked 'DB _ FIELDS_CACHE' => true, // enable the field cache 'DB _ charset' => 'utf8', // The database encoding uses utf8 by default);?>
(2) create a table:
CREATE TABLE `think_user` ( `id` int(11) DEFAULT NULL, `name` varchar(30) DEFAULT NULL, `pwd` varchar(20) DEFAULT NULL) ENGINE=InnoDB;
(3) execute the data insert operation and modify the IndexAction. class. php file under lib/Action. The content is as follows:
<?phpclass IndexAction extends Action{ function index(){ public function index(){ $data=array( "id"=>"1", "name="=>"liuning", "pwd"=>"asd123" ); M("user")->add($data); } }}?>
(4) execute http: // localhost/xmall/index. php to generate new records in the database;
PS: We recommend several formatting and beautification tools on this site. I believe you can use them in future development:
Php code online formatting and beautification tools:
Http://tools.jb51.net/code/phpformat
JavaScript code beautification/compression/Formatting/encryption tools:
Http://tools.jb51.net/code/jscompress
Online XML formatting/compression tools:
Http://tools.jb51.net/code/xmlformat
JSON code formatting and beautification tools:
Http://tools.jb51.net/code/json
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
SQL code online formatting and beautification tools:
Http://tools.jb51.net/code/sqlcodeformat