Thinkphp always fails to connect to the mysql database

Source: Internet
Author: User
When I connect to a database using the thinkphp framework, it will never be connected. The Code is as follows: config. php {code ...} then access the database through methods in the class. The USER is the database name publicfunctiontest () {code ...} when I connect to a database using the thinkphp framework, it will never be connected.
The Code is as follows:
Config. php

Return array (// 'config maps '=> 'configuration value' // static MODULE Access // 'module _ DENY_LIST' => array ('common', 'runtime ', 'admin'), // allow access // 'module _ ALLOW_LIST '=> array ('home', 'admin '), // The default loading module 'db _ type' => 'mysql', 'db _ host' => 'localhost: 8080 ', 'db _ user' => 'root ', 'db _ pwd' => '000000', 'db _ port' => '000000', 'db _ name' => 'thinkphp ', 'db _ prefix' => 'think _',);

Then access the database through methods in the class. The USER is the name of the database.
Public function test (){

$ User = new Model ('user'); // connection to the database var_dump ($ User-> select ();} He is always unsuccessful. Why.

Reply content:

When I connect to a database using the thinkphp framework, it will never be connected.
The Code is as follows:
Config. php

Return array (// 'config maps '=> 'configuration value' // static MODULE Access // 'module _ DENY_LIST' => array ('common', 'runtime ', 'admin'), // allow access // 'module _ ALLOW_LIST '=> array ('home', 'admin '), // The default loading module 'db _ type' => 'mysql', 'db _ host' => 'localhost: 8080 ', 'db _ user' => 'root ', 'db _ pwd' => '000000', 'db _ port' => '000000', 'db _ name' => 'thinkphp ', 'db _ prefix' => 'think _',);

Then access the database through methods in the class. The USER is the name of the database.
Public function test (){

$ User = new Model ('user'); // connection to the database var_dump ($ User-> select ();} He is always unsuccessful. Why.

Configuration'DB_HOST'=>'localhost:8080'Remove Port

Only the address is entered in DB_HOST. You should not understand the role of the configuration file. The remaining ports are configured by default or special by DB_PORT,
Even if an error occurs, you can use M ()-> getError () to obtain the error message.

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.