我在mysql中执行下面的查询,但它不起作用。给出以下错误,
警告:mysql_num_rows()期望参数1为资源,第228行/usr/share/info/.info/php/userutil.php中给出布尔值
这是我的代码:
echo $con = mysql_connect('localhost', 'root', 'root123','qhutm');
if(!$con){
echo 'connection failed';
}else{
echo 'conn successful';
}
$query ="SELECT no_of_license
FROM Service_Master AS s,Service_Details AS d
WHERE s.service_id=d.service_id
AND s.description='Internet Access' ";
$result = mysql_query($query,$con)
print_r($result);
echo $result.'--pra';
echo mysql_num_rows($result);
conn successful
如果我在mysql上回显并执行相同的查询,它可以正常工作
如果我回复$con
,则会给出Resource id #126
答案 0 :(得分:1)
也许你使用普通加入?
select no_of_license
from Service_Master as s
join Service_Details as d on s.service_id = d.service_id
where s.description = 'Internet Access'
答案 1 :(得分:0)
尝试JOIN
喜欢
"SELECT no_of_license
FROM Service_Master AS s,
LEFT JOIN Service_Details AS d
ON s.service_id=d.service_id
WHERE s.description='Internet Access'
答案 2 :(得分:0)
$query ="SELECT XXXXX FROM `Service_Master` s, `Service_Details` d WHERE s.service_id=d.service_id AND s.description='Internet Access' ";
replace it
and also XXXXX if no_of_license field in Service_Master this table write s.`no_of_license`
else if this field is in Service_Details than write d.`no_of_license`
i think its work fine
答案 3 :(得分:0)
您尚未选择数据库,请使用mysql_select_db()
您的连接应该是这样的
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('foo', $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>
答案 4 :(得分:0)
您在创建数据库连接后忘记选择数据库 请在创建与数据库的连接后添加以下行。
mysql_select_db('qhutm',$ con);