thinkphp connection to MySQL database is always unsuccessful

Source: Internet
Author: User
Keywords Php
When I use the thinkphp framework to connect to a database, it is always connected.
The code is as follows
config.php





return array(
     //'Configuration Item'=>'Configuration Value'
     //Static module access
     //'MODULE_DENY_LIST' => array('Common','Runtime','Admin'),
    
     //Allow access
     //'MODULE_ALLOW_LIST' => array('Home','Admin'),
     //Load module by default
 
         'DB_TYPE'=>'mysql',
         'DB_HOST'=>'localhost:8080',
         'DB_USER'=>'root',
         'DB_PWD'=>'123456789',
         'DB_PORT'=>'3306',
         'DB_NAME'=>'thinkphp',
         'DB_PREFIX'=>'think_',

);


And then in the class through method access, user is the name of the database
Public Function test () {



$user=new Model('User'); //Connect to the database
     var_dump($user->select());

  }
  He is always unsuccessful, what is the reason for this.





Reply content:



When I use the thinkphp framework to connect to a database, it is always connected.
The code is as follows
config.php



return array(
     //'Configuration Item'=>'Configuration Value'
     //Static module access
     //'MODULE_DENY_LIST' => array('Common','Runtime','Admin'),
    
     //Allow access
     //'MODULE_ALLOW_LIST' => array('Home','Admin'),
     //Load module by default
 
         'DB_TYPE'=>'mysql',
         'DB_HOST'=>'localhost:8080',
         'DB_USER'=>'root',
         'DB_PWD'=>'123456789',
         'DB_PORT'=>'3306',
         'DB_NAME'=>'thinkphp',
         'DB_PREFIX'=>'think_',

);


And then in the class through method access, user is the name of the database
Public Function test () {



$user=new Model('User'); //Connect to the database
     var_dump($user->select());

  }
  He is always unsuccessful, what is the reason for this.





Configure 'DB_HOST'=>'localhost:8080'remove port '






Db_host inside just fill in the address, you should not understand the role of the configuration file, the rest of the port is the default or special by the Db_port to configure,
Even if something goes wrong, you can get the error message via M ()->geterror ().

Related Article

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.