About database field name capitalization in thinkphp

Source: Internet
Author: User
Tags lowercase php file

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.

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.