简体   繁体   English

PHP中是否有函数或命令来解决为什么未将数据插入sql数据库的问题?

[英]Is there a function or command in PHP to troubleshoot why data is not being inserted into a sql database?

I've been trying to get images to insert into my db for two weeks now. 我一直在尝试将图像插入到数据库中已有两个星期了。 Just wondering if there was any way to get specific info on why in order to troubleshoot it (by means of a PHP function or something of the sort). 只是想知道是否有任何方法可以获取有关为何进行故障排除的特定信息(通过PHP函数或类似的方式)。

To be clearer, I'm asking if there is a way to generate an error message describing exactly the reason the data was not inserted, rather than writing out if/else statements for each individual situation (such as if not connected to database, wrong data type, etc.) 更清楚地说,我在问是否有一种方法可以生成一条错误消息,准确描述未插入数据的原因,而不是针对每种情况写出if / else语句(例如,如果未连接到数据库,则错误数据类型等)

I've avoided code specifics as the last two got marked down and I'm about to be banned. 我避免了代码细节,因为最后两个代码已被标记下来,而且我将被禁止。 Thank you. 谢谢。

Yes there is, try mysql_error or mysqli_error 是的,请尝试mysql_errormysqli_error

For example: 例如:

if (!mysqli_query($con,"INSERT INTO Persons (FirstName) VALUES ('Glenn')")){
    echo("Error description: " . mysqli_error($con));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM