Home  >  Article  >  Backend Development  >  thinkphp configuration and connection database skills, thinkphp database skills_PHP tutorial

thinkphp configuration and connection database skills, thinkphp database skills_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:12:39720browse

thinkphp configuration and connection database skills, thinkphp database skills

The example in this article describes the common methods of thinkphp configuration and connection to the database, and is shared with everyone for your reference. The specific method is as follows:

1. Add database configuration information to config.inc.php in the same directory as the thinkphp entry file

Copy code The code is as follows:
return array(
'DB_TYPE'=>'mysqli',
'DB_HOST'=>'localhost',
'DB_NAME'=>'demo',
'DB_USER'=>'root',
'DB_PWD'=>'root',
'DB_PREFIX'=>'think_',
);
?>

Then add the following code to the config.php file in the project directory:
Copy code The code is as follows:
$arr1=array(
//'Configuration item'=>'Configuration value'
'URL_MODEL'=>2,
'APP_DEBUG'=>true,
'LOG_RECORD'=>true,
......
);
$arr2=include 'config.inc.php';
return array_merge($arr1,$arr2);
?>

You can also add the above code to the background file, so that after the connection information of the database configuration is changed, you only need to modify the information in the config.inc.php file to modify the database connection configuration information of the foreground and the background at the same time.

2. If you want to connect to another database in the controller you can do it by adding the following code:

Copy code The code is as follows:
$arrr=array(
'dbms'=>'mysqli', //Note that the key names in this book group are specified and cannot be changed.
'username'=>'google',
'password'=>'hello',
'hostname'=>'127.0.0.1',
'database'=>'MYDBname',
);
$db=new Db($arrr);

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920609.htmlTechArticlethinkphp configuration and connection database skills, thinkphp database skills This article describes the common methods of thinkphp configuration and connection database, share it with everyone For your reference. The specific method is as follows:...
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