我正在尝试让这个语句起作用......我正在检查$ batchid是否存在,如果确实存在,则停止处理脚本。
if (mysql_num_rows(mysql_query("select batch_id from load_test
where batch_id='".$batchid."'")) > 0) {
die("Error batch already present");
}
答案 0 :(得分:3)
首先,确保使用mysql_real_escape_string转义$ batchid。
此代码应该有效(非区分大小写):
if (mysql_result(mysql_query("SELECT COUNT(*) FROM load_test WHERE batch_id='".$batchid."'"), 0) > 0) {
die("Error batch already present");
}
区分大小写的版本(source):
if (mysql_result(mysql_query("SELECT COUNT(*) FROM load_test WHERE batch_id LIKE BINARY '".$batchid."'"), 0) > 0) {
die("Error batch already present");
}
答案 1 :(得分:0)
简单地写一下:
$res=mysql_query("select count(*) from load_test where batch_id='".$batchid."'");
if($res>0)
{
die("Error batch already present");
}