zoukankan      html  css  js  c++  java
  • tp数据库表大写命名的一些问题

    在使用thinkphp时,如果数据库表命名有大写,会被转换成小写加下划线(可以使用$model->_sql())来查看实际执行的sql是什么

    这个问题,看了一下源代码,在 Thinkphp/Common/common.php里面,这个函数会将数据表(或视图)的大写字母转换为下划线+小写:

     1 function parse_name($name, $type=0) {
     2     if ($type) {
     3         return ucfirst(preg_replace("/_([a-zA-Z])/e", "strtoupper('\1')", $name));
     4     } else {
     5         return strtolower(trim(preg_replace("/[A-Z]/", "_\0", $name), "_"));
     6         //<feixiang 2013年7月6日 这里会将数据库表名里的大写转换为 _小写,这里不转换,在Model.class.php还将表转换成了小写,需要改一下 >
     7         //echo $name ;
     8         //return $name;
     9     }
    10 }

    另外,在 Thinkphp/Core/Model.class.php里面,会将整个表名转换成小写:

     1     public function getTableName() {
     2         if(empty($this->trueTableName)) {
     3             $tableName  = !empty($this->tablePrefix) ? $this->tablePrefix : '';
     4             if(!empty($this->tableName)) {
     5                 $tableName .= $this->tableName;
     6             }else{
     7                 $tableName .= parse_name($this->name);
     8             }
     9             //<feixiang 这里会将表名转换成小写,我们这里不转换>
    10             $this->trueTableName    =   strtolower($tableName);
    11             //$this->trueTableName    =   $tableName;
    12         }
    13         return (!empty($this->dbName)?$this->dbName.'.':'').$this->trueTableName;
    14     }

    这样有好处——规范。

    但是在我们的开发中,有大写的数据表,所以改了一下(注释的那些)...

    或者可以在模型定义里面加上:

    protected $trueTableName = 'myTableName';

    来覆盖$this->trueTableName

  • 相关阅读:
    修改weblogic jvm启动参数
    weblogic部署步骤
    weblogic安装步骤
    sqldeveloper 导出数据库
    VO与PO 的理解
    【Hyper-V】与【VirtualBox】【VMware】冲突的解决方法
    xstream 实现simplebean2xml ,xml2simplebean
    eclipse中SVN报错解决
    点击eclipse包报错
    myeclipce项目导入eclipse中报错
  • 原文地址:https://www.cnblogs.com/trying/p/3174189.html
Copyright © 2011-2022 走看看