PHP如何判断INSERT是否插入成功

PHPz
Release: 2020-06-28 09:33:31
Original
3038 people have browsed it

PHP如何判断INSERT是否插入成功

PHP如何判断INSERT是否插入成功?

具体问题:

在PHP中,用mysql_query执行一个INSERT语句后,在MYSQL控制台可查到查询成功,可是该怎么用代码判断这个语句是否执行成功?

在百度里查的这个函数返回值就是TRUE或者FALSE,但是我这边执行不管对错都是返回0呢?

解决办法:

使用PDO。

insert完成后调用$db->lastInsertid();查询最后一次插入返回的id。或者查看affected_rows

更多相关技术文章,请访问PHP中文网

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!