[TOC]
## 獲取原始的數據表名 **tablename()**
~~~
tablename($table)
~~~
| | |
| -- | -- |
| $table | string 數據庫中不帶表前綴的表名 |
|返回值|string 原始表名, 可以直接用于數據庫查詢操作|
> 微擎系統按照慣例在所有的表名增加了前綴來增強兼容性.使用 tablename() 函數, 方便將業務數據表名轉換為原始的數據表名來進行數據庫操作.
~~~
function tablename($table) {
if(empty($GLOBALS['_W']['config']['db']['master'])) {
$GLOBALS['_W']['config']['db']['master'] = $GLOBALS['_W']['config']['db'];
}
$db = &$GLOBALS['_W']['config']['db'];
$db['slave_except'] = false;
if($db['slave_status'] == true && !empty($db['common']['slave_except_table']) && in_array($table, $db['common']['slave_except_table'])) {
$db['slave_except'] = true;
}
return "`{$db['master']['tablepre']}{$table}`";
}
~~~