[英]sql in php not returning anything
How do I see what is returned from a sql statement in php? 我如何查看php中的sql语句返回什么? I have the following function to get user name from mysql database and I use echo in another php to see the result but nothing shown.
我有以下功能从mysql数据库获取用户名,并且在另一个php中使用echo来查看结果,但未显示任何内容。
function get_user_name($id_user) {
return mysql_result(mysql_query("SELECT username FROM user WHERE id_user = '$id_user'"));
}
echo $id_user;
$a = get_user_name($id_user);
echo $a;
Can anyone help? 有人可以帮忙吗? Thanks.
谢谢。
Are you echo
ing the get_user_name();
您是否正在
echo
get_user_name();
function?? 功能?? OR are you even connected to your database?
或者您是否已连接到数据库? these are two things you need to check before, (if the problem remains) including an error handling method ie
or die(mysql_error())
at the end of your query to find out the problem. 这是您需要检查的两件事,如果问题仍然存在,则需要在查询末尾包括错误处理方法(即
or die(mysql_error())
以查找问题。
return mysql_result(mysql_query("SELECT id_user FROM user WHERE id_user = '$id_user'")or die (mysql_error()));
The error handling construct?? 错误处理构造? in mysql
mysql_error()
should output the problem in fairly understandable way, as to what is preventing your query not to be shown 在mysql中
mysql_error()
应该以一种可以理解的方式输出问题,以防止您的查询无法显示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.