Home  >  Article  >  Backend Development  >  How to connect thinkphp3.x to mysql database (specific steps), thinkphp3.xmysql_PHP tutorial

How to connect thinkphp3.x to mysql database (specific steps), thinkphp3.xmysql_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:52:20711browse

How to connect thinkphp3.x to mysql database (specific steps), thinkphp3.xmysql

This article describes the method of thinkphp3.x to connect to mysql database. Share it with everyone 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:

<&#63;php
return array(
   //'配置项'=>'配置值'
   /* 数据库设置 */
    'DB_TYPE'    => 'mysql',  // 数据库类型
    'DB_HOST'    => 'localhost', // 服务器地址
    'DB_NAME'    => 'xmall',  // 数据库名
    'DB_USER'    => 'root',  // 用户名
    'DB_PWD'    => '123', // 密码
    'DB_PORT'    => '3306',  // 端口
    'DB_PREFIX'    => 'think_', // 数据库表前缀
    'DB_FIELDTYPE_CHECK' => false,  // 是否进行字段类型检查
    'DB_FIELDS_CACHE'  => true,  // 启用字段缓存
    'DB_CHARSET'   => 'utf8',  // 数据库编码默认采用utf8
);
&#63;>

(2) Create table:

CREATE TABLE `think_user` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(30) DEFAULT NULL,
  `pwd` varchar(20) DEFAULT NULL
) ENGINE=InnoDB;

(3) Perform data insertion operation and modify the IndexAction.class.php file under lib/Action, the content is as follows:

<&#63;php
class IndexAction extends Action{
   function index(){
     public function index(){
       $data=array(
          "id"=>"1",
          "name="=>"liuning",
         "pwd"=>"asd123"
       );
       M("user")->add($data);
     }
   }
}
&#63;>

(4) Execute http://localhost/xmall/index.php, and new records will be generated in the database;

PS: Here are several formatting and beautification tools recommended for this site. I believe everyone can use them in future development:

php code online formatting and beautification tool:
http://tools.jb51.net/code/phpformat

JavaScript code beautification/compression/formatting/encryption tool:
http://tools.jb51.net/code/jscompress

Online XML formatting/compression tool:
http://tools.jb51.net/code/xmlformat

JSON code formatting and beautification tool:
http://tools.jb51.net/code/json

Online XML/JSON conversion tool:
http://tools.jb51.net/code/xmljson

SQL code online formatting and beautification tool:
http://tools.jb51.net/code/sqlcodeformat

Readers who are interested in more thinkPHP-related content can check out the special topics on this site: "ThinkPHP Getting Started Tutorial", "ThinkPHP Common Methods Summary", "Smarty Template Basic Tutorial" and "PHP Template Technology Summary".

I hope this article will be helpful to everyone’s PHP programming based on the ThinkPHP framework.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127839.htmlTechArticleHow to connect thinkphp3.x to mysql database (specific steps), thinkphp3.xmysql This article describes thinkphp3.x with examples How to connect to mysql database. Share it with everyone for your reference, specifically...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn