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 ().