以下SQL语句在SQL脚本或phpmyadmin中对MySQL数据库表正确运行,但在PHP脚本中运行时会出错。
SQL语句为:
update traceability t1 inner join traceability t2 on (t1.parent in (select t2.child)) set t1.root=false;在PHP脚本中,代码如下所示:
$sqlupdatestmt = $db->query("update traceability t1 inner join traceability t2 on (t1.parent in (select t2.child)) set t1.root=false;");
$sqlupdatestmt->execute();PHP日志中的错误是:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 't2.child' in 'field list'' in /<myfilepath> /traceability.php:50
Stack trace:
#0 /<myfilepath>/traceability.php(50): PDO->query('update traceabi...')
#1 {main}PHP抛出PHP/SQL错误的地方出了什么问题?
以下是有关可跟踪性表模式的信息:
Field Type Null Key Default Extra
Variant varchar(20) YES MUL NULL
Parent varchar(50) YES NULL
Child varchar(50) YES NULL
Relation varchar(20) YES NULL
Root tinyint(1) YES NULL
Leaf tinyint(1) YES NULL发布于 2014-10-17 22:46:17
试一试
UPDATE traceability AS t1 set t1.root=false WHERE t1.parent IN (SELECT child FROM traceability)
自动分析
发布于 2014-10-17 23:22:24
看起来您正在尝试执行自联接,以便将任何子节点的值设置为root = 'false‘。它应该看起来像这样:
UPDATE traceability AS t1
INNER JOIN traceability AS t2
ON t1.parent = t2.child
SET t1.root='false'在您的表中有一个双向的子-父引用似乎也不常见。根本不是一个公共的表模式。你是说每个父母只能有一个孩子吗?
https://stackoverflow.com/questions/26427376
复制相似问题