简体   繁体   English

mssql_query 可以检测到插入错误吗?

[英]Can mssql_query detect inserting error?

I am trying to detect inserting result.我正在尝试检测插入结果。

When I tried to insert with INSERT INTO table (1,2,'t') this will result in inserting error because of the third column of my table is decimal type,but mssql_query will return true.当我尝试使用INSERT INTO table (1,2,'t')插入时,这将导致插入错误,因为我的表的第三列是十进制类型,但 mssql_query 将返回 true。

but when I tested with INSET INTO table (1,2,'t') this will return false,like it should.但是当我使用INSET INTO table (1,2,'t')进行测试时,这将返回 false,就像它应该的那样。

Why the first statement returning true?为什么第一条语句返回 true? and how can we check that it is an error not true!!以及我们如何检查这是不是一个错误!

Correct syntax is:正确的语法是:

insert into table_name (column_name1, column_name2, ..) 
VALUES (value_of_column1, value_of_column2, ..)

As you already know ordering part is not required, but i highly suggest you to do ordering first and then give values to it.正如您已经知道订购部件不是必需的,但我强烈建议您先订购,然后为其赋值。

mysql_query return false on error and you can get error by using mysql_error function. mysql_query 在错误时返回 false,您可以使用 mysql_error function 得到错误。

And keep this in your mind that you should surround values by quotations only when you are filling columns with type of varchar/char/date/datetime..记住这一点,只有在填充类型为 varchar/char/date/datetime.. 的列时,才应该用引号将值括起来。

Other types like boolean, int, decimal and.. should be provided without quotations.其他类型,如 boolean、int、decimal 和.. 应不带引号提供。

Hope it solve your problem;)希望它能解决你的问题;)

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

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