使用PHP验证SQL查询 [英] Validating SQL query with PHP
本文介绍了使用PHP验证SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
验证似乎由于某种原因而失败。通过验证,我的意思是 if($ result)
部分。如何正确验证SQL查询?
The validation seems to fail for some reason. By the validation, I mean the "if ($result)
" -part. How can I correctly validate SQL-query?
$dbconn = pg_connect("host=localhost port=5432 dbname=heoa user=heoa password=123");
$email = $_POST['login']['email'];
$result = pg_query_params( $dbconn,
'SELECT user_id
FROM users
WHERE email = $1',
array( $email )
);
if ($result)
{
while ( $row = pg_fetch_array( $result ) )
{
$user_id = $row['user_id'];
}
return $user_id;
}
推荐答案
我怀疑返回值是整数零,在if语句中也解释为false。通过执行 if($ result!== FALSE)(请注意,应该为!==和 not !=),您将验证结果是否确实是与FALSE不同,而不仅仅是假...
I suspect that the return value is integer zero which is also interprested as false in the if statement. By doing "if ($result !== FALSE)" (Note that it should be !== and not !=) you'll verify if the result really is different than FALSEand not just false...
这篇关于使用PHP验证SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文