Today, when using the thinkphp framework to make a Web site, it is an unexpected occurrence when calling the model Fatal error: uncaught exception ' pdoexception ' with message ' sqlstate[ 42S02] Error,
The following is my Baidu results, most of the problem can be divided into the following two categories:
1.
Under Windows iis7.5+php5.4.11 (FastCGI)
Missing PDO, editing php.ini
Uncomment:
Extension=php_pdo_mysql.dll
Restart IIS
The PHP Data Object (PDO) extension defines a lightweight, consistent interface to access the database. Each driver that implements the PDO interface exhibits database-related features like a generic extension function. You cannot perform any database functions with the PDO function itself. You must use a database-related driver to access the database server.
PDO provides a data access abstraction layer, meaning that you can publish queries and retrieve data using the same functions without knowing what database you are using.
2. Modify the code:
This situation (Undefined class constant ' Mysql_attr_init_command ') is a PHP5.3.0 bug, see http://bugs.php.net/bug.php?id=47224
There are two ways to solve the problem, one is to change the code
$pdb = new PDO ("Mysql:host=localhost;dbname=test", ' root ');
$pdb->exec ("SET NAMES UTF8");
The second is to upgrade your PHP to a higher version
To the above users of the answer I myself tinker for a long time also did not solve, finally in their own research found the solution is actually very simple:
The TP operation model is similar to the hibernait Operation data table in JSP, the model name you want to manipulate must correspond to your table name, which is a way
Another way is: protected $trueTableName = "; invoke the statement to manipulate the real data table
About errors in the Thinkphp framework model application process undefined class constant Mysql_attr_init_command