Thinkphp3.x connection to the mysql database (specific operation steps), thinkphp3.xmysql _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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

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.