Wishlist 0 ¥0.00

使用‘##__’替换表前缀,也很方便

在很多时候,我需要使用sql语句,这样就会使用到类似__TABLENAME__样的表名称,但打字起来并不顺手,我希望简便一些,借鉴了他人的处理方式,使用##__代替表前缀,清晰可辨,书写简易。

例如:

$sql = "SELECT * FROM ##__tablename WHERE cat_id=100";

解析后的$sql为:

"SELECT * FROM shop_tablename WHERE cat_id=100";


要做到这样的效果,需要变化两个地方:



1.在ThinkPHP/Library/Think/Model.class.php的 1417 行附近,

把:
$sql = strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>$this->tablePrefix));

修改为:
//$sql = strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>$this->tablePrefix));
$sql = strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>$this->tablePrefix, C('SQL_REPLACE')=>$this->tablePrefix)); //添加##__替换表前缀




2.在数据库配置中,加上一句:

'SQL_REPLACE' => '##__', //替换表前缀



3.删除Runtime缓存后,就可以使用了。

About Us

Since 1996, our company has been focusing on domain name registration, web hosting, server hosting, website construction, e-commerce and other Internet services, and constantly practicing the concept of "providing enterprise-level solutions and providing personalized service support". As a Dell Authorized Solution Provider, we also provide hardware product solutions associated with the company's services.
 

Contact Us

Address: No. 2, Jingwu Road, Zhengzhou City, Henan Province

Phone: 0086-371-63520088 

QQ:76257322

Website: 800188.com

E-mail: This email address is being protected from spambots. You need JavaScript enabled to view it.