In the use of thinkphp, I encountered the database field name case, using the M () method, thinkphp will look for lowercase database fields by default, through the following methods to resolve: is to modify the thinkphp of the source code in library/db/ Driver.class.php file, put
Pdo::attr_case => Pdo::case_lower
To
Pdo::attr_case => pdo::case_natural
Or add to the configuration file
' Db_params ' => array (\pdo::attr_case => \pdo::case_natural)
This sentence. The first time the use of this solution can be, but do another project is always not effective, helpless, Baidu for a half-day, find a way, because the thinkphp when the default will be converted to lowercase, so we find its source code does not let it convert on the line. Modify common/functions.php inside the Parse_name function source is:
function Parse_name ($name, $type =0) {/
* if ($type) {return
Ucfirst (preg_replace_callback ('/_ ') ([a-za-z] )/', function ($match) {return Strtoupper ($match [1]);}, $name));
else {
//This will convert the capitalization of the database table name to _ lowercase, modified to not convert return
strtolower (Trim (preg_replace ("/[a-z]/", "_\\0", $name), "_ "));
} *
/return $name;}
The annotation is out of the original, and no comments are added. Modify the Gettablename function inside the library/think/model.class.php:
$this->truetablename = Strtolower ($tableName); The table name will be converted to lowercase, modified to not convert $this->truetablename = $tableName;
Modify one of the sentences so that you can resolve the problem of capitalizing the database field name.