首页 测试 管理 查看内容

TP数据库表大写命名的一些问题

2014-7-30 14:16| 发布者: peter_zhang| 查看: 504| 评论: 0

摘要:   在使用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]/", "_", $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
  在使用thinkphp时,如果数据库表命名有大写,会被转换成小写加下划线(可以使用$model->_sql())来查看实际执行的sql是什么  这个问题,看了一下源代码,在 Thinkphp/Common/common.php里面,这个函数会将数据表(或视图)的大写字母转换为下划线+小写:

鲜花

握手

雷人

路过

鸡蛋

扫一扫关注最新动态

毒镜头:老镜头、摄影器材资料库、老镜头样片、摄影
爱评测 aipingce.com  
返回顶部