$table1="tab1";
$table2="tab2";
$query=sprintf("SELECT '%s'.* FROM '%s' JOIN '%s' ON ('%s'.id='%s'.id)",
$table1,
$table1,
$table2,
$table1,
$table2);
$query=$this->db->query($query);
return $query->num_rows();
得到约束的记录行数,我想出了下面的错误,我使用最新的XAMPP使用MySQL 5.1版
错误编号:1064
您的SQL语法错误;在第1行检查手册 对应于您的MySQL服务器版本的正确语法在'。* FROM'tab1'JOIN'tab2'ON ('tab1'.userid ='tab2'.userid)'附近使用
SELECT 'TAB1' * FROM 'TAB1' 加入 'TAB2' ON ( 'tab1'.userid =' tab2'.userid)
文件名:A:\ CodeIgniter_2.1.0 \ SYSTEM \数据库\ DB_driver .PHP
行号:330
UPDATE
$query=sprintf("SELECT `%s`.* FROM `%s` JOIN `%s` ON (`%s`.id=`%s`.id) LIMTI `%d`, `%d`",
$table1,
$table1,
$table2,
$table1,
$table2,
$num1,
$num2);
误差
错误编号:1327
未声明的变量:5
SELECT
tab1
* FROMtab1
JOINtab2
ON (tab1
.userid =tab2
.userid)LIMIT5
,0
文件名:A:\ CodeIgniter_2.1.0 \ SYSTEM \数据库\ DB_driver.php
行号:330
在表名称周围使用反引号(')而不是撇号。撇号用于MySQL中的字符串值。 – Farray 2012-02-13 03:41:51
它的工作原理,谢谢Farray。 – user1125233 2012-02-13 03:51:55