简体   繁体   English

如何检查表是否为空,php和mysql中的Execute和FetchRow方法

[英]How to check if table is empty , Execute and FetchRow methods in php and mysql

$RSGetID = $this->MyDBObject->Prepare("SELECT FinalID FROM clothes 
WHERE ClothID=:|1 AND PriceID = :|2 LIMIT 1");

$RSGetID->Execute(2, 199);

$ClothIDRow = $RSGetID->FetchRow();  

return $ClothIDRow->FinalID;

This last line gives an error, because there are no rows in the table, so it says: 最后一行给出了错误,因为表中没有行,所以它说:

"the query did not return any records" “查询未返回任何记录”

How do I put a condition, that if the table is empty then return 0 , else return the fetched FinalID from the database table? 如何设置条件,如果表为空则返回0,否则返回从数据库表中获取的FinalID

You're using some custom DB layer (MyDBObject?) rather than straight-up PDO - it's impossible for us to know how this behaves. 您正在使用一些自定义数据库层(MyDBObject?),而不是直接使用PDO-我们无法知道其行为。 There's probably a method along the lines of ->RowCount() or ->NumRows() you can call to see if you got anything back after the ->Execute() - but this is just guessing, since I can't see the DB object you're using. 大概有一个方法-> RowCount()或-> NumRows()可以调用以查看-> Execute()之后是否返回了任何内容-但这只是猜测,因为我看不到您正在使用的数据库对象。

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

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