gpt4 book ai didi

php - 无法选择“FROM WHERE”?

转载 作者:行者123 更新时间:2023-11-29 06:21:52 24 4
gpt4 key购买 nike

我有这段代码,但奇怪的是它总是回显“是!”,即使 FLD2 中没有“555”这样的值,或者即使根本没有 FLD2。

$testresult = mysqli_query($database, "SELECT * FROM imei359327039828680 WHERE FLD2 = '555'");

if ( $testresult ) { echo('yes!'); } else { echo('no!'); }

任何想法,谢谢!

最佳答案

正如 ctshryock 所提到的,设置为格式正确的 SQL 查询的返回值的变量在作为 bool 对象查看时将始终被视为 true

要测试是否返回任何数据,您可以使用mysql_num_rows() PHP Documentation这将返回返回的行数。如果您的查询不匹配任何行,则此函数应返回 0if() 条件会将其视为 false

$testresult = mysql_query( "SELECT * FROM imei359327039828680 WHERE FLD2 = '555'" );

if( !$testresult )
die( 'SQL Error' ); # The SQL Query Failed for some reason

if( mysql_num_rows( $testresult ) )
die( 'SQL Returned No Result' ); # The SQL Query returned nothing

while( $r = mysql_fetch_assoc( $testresult ) ) {
# Process your returned rows here
}

关于php - 无法选择“FROM WHERE”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2930381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com