$cdb=new \PDO('mysql:dbname=crawler;host=127.0.0.1;charset=utf8','root','*****');
$cdb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$sql='update jb51_ps_article set is_handle=1 and new_article_id=5 where id=71665';
$state=$cdb->exec($sql);
print_r($cdb->errorInfo());
这里的update语句的set部分写错了set ishandle=1 and newarticle_id=5
立即学习“PHP免费学习笔记(深入)”;
$sql='update jb51_ps_article set is_handle=1 and new_article_id=5 where id=71665';
应该为set ishandle=1,newarticle_id=5
执行后数据表不会更改,但是没有任何错误信息,害得我弄了半天,不知道是怎么回事?
下面是输出信息:
$cdb=new \PDO('mysql:dbname=crawler;host=127.0.0.1;charset=utf8','root','*****');
$cdb->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$sql='update jb51_ps_article set is_handle=1 and new_article_id=5 where id=71665';
$state=$cdb->exec($sql);
print_r($cdb->errorInfo());
这里的update语句的set部分写错了set ishandle=1 and newarticle_id=5
立即学习“PHP免费学习笔记(深入)”;
$sql='update jb51_ps_article set is_handle=1 and new_article_id=5 where id=71665';
应该为set ishandle=1,newarticle_id=5
执行后数据表不会更改,但是没有任何错误信息,害得我弄了半天,不知道是怎么回事?
下面是输出信息:
创建PDO对象的时候设置一下错误模式
$cdb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
然后try/catch一下就可以捕获到错误了
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号