duanlou2917 2014-10-17 14:36
浏览 80

PHP中的SQL语句错误,但SQL中的错误

The following SQL statement runs correctly against a MySQL database table in an SQL script or in phpmyadmin but errors when run from within a PHP script.

The SQL statement is:

update traceability t1 inner join traceability t2 on (t1.parent in (select t2.child)) set t1.root=false;

in the PHP script the code looks like:

$sqlupdatestmt = $db->query("update traceability t1 inner join traceability t2 on (t1.parent in (select t2.child)) set t1.root=false;");
$sqlupdatestmt->execute();

The error in the PHP log is:

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}

What's going wrong in the PHP that it throws a PHP/SQL error?

Here is information on traceability table schema:

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
  • 写回答

2条回答 默认 最新

  • doupu7651 2014-10-17 14:46
    关注

    Try

    UPDATE traceability AS t1 set t1.root=false WHERE t1.parent IN (SELECT child FROM traceability)

    Anas

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀