【发布时间】:2012-03-04 13:04:04
【问题描述】:
我通过使用获取约束记录上的行数
$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 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 靠近'.* FROM 'tab1' JOIN 'tab2' ON ('tab1'.userid='tab2'.userid)' 在第 1 行
SELECT 'tab1'.* FROM 'tab1' 加入 'tab2' ON ('tab1'.userid='tab2'.userid)
文件名:A:\CodeIgniter_2.1.0\system\database\DB_driver.php
行号:330
更新
$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
选择
tab1.* FROMtab1加入tab2ON (tab1.userid=tab2.userid) 限制5,0文件名:A:\CodeIgniter_2.1.0\system\database\DB_driver.php
行号:330
【问题讨论】:
-
在表名周围使用反引号 (`) 而不是撇号。撇号用于 MySQL 中的字符串值。
-
它有效,谢谢 Farray。
标签: php mysql codeigniter xampp