When I use thinkphp, I have encountered the case-sensitivity problem of database field names. When I use the M () method, thinkphp searches for lower-case database fields by default. The solution is as follows:
Modify the Library/Db/Driver. class. Php file in the thinkphp source code
PDO: ATTR_CASE => PDO: CASE_LOWER changed to PDO: ATTR_CASE => PDO: CASE_NATURAL,
Or add
DB_PARAMS '=> array (\ PDO: ATTR_CASE => \ PDO: CASE_NATURAL.
This solution works for the first time, but it never works for another project. However, Baidu has found a solution for a long time, because thinkphp converts uppercase letters to lowercase letters by default, we can find the source code of thinkphp so that it cannot be converted.
Modify the source code of the parse_name function in Common/functions. php:
Function parse_name ($ name, $ type = 0 ){
/* If ($ type ){
Return ucfirst (preg_replace_callback ('/_ ([a-zA-Z])/', function ($ match) {return strtoupper ($ match [1]);}, $ name ));
} Else {
// Here, the upper case of the database table name is converted to the lower case, and the change is not converted.
Return strtolower (trim (preg_replace ("/[A-Z]/", "_ \ 0", $ name ),"_"));
}*/
Return $ name;
}
The comments are original, but not added.
Modify the getTableName function in Library/Think/Model. class. php:
// $ This-> trueTableName = strtolower ($ tableName); // The table name is converted to lowercase and not converted here.
$ This-> trueTableName = $ tableName;
Modify one of these statements to solve the problem of database field name capitalization.