wamp安装后phpadmin能打开但是为什么数据库还是连接不了显示MySQL-Link resource

源代码:messtest是数据库名称,gbbook是表名,在图形化界面中可以查询成功
<?php
$conn=mysql_connect("localhost","root","1234","messtest");
if (empty($conn)) {
die("不能连接数据库服务器:".mysql_connect_errror());
}
mysql_select_db('messtest');
mysql_query($conn,"setnames utf8");
mysql_query("set names 'GBK'"); //使用GBK中文编码;
$results = $conn->query("SELECT * from gbbook");
while($rows = $results->fetch_row()){
echo($rows[0]."".$rows[1]."".$rows[2]."".$rows[3]."<BR>");
}
$results->free();
mysqli_close($conn);
?>
修改之后
<?php
$conn=mysql_connect("localhost","root","1234","messtest") or die("不能连接数据库服务器:".mysql_connect_errror());
mysql_select_db("messtest",$conn);
$results = mysql_query("select * fron gbbook");
mysql_query($results,$conn);
mysql_query("setnames utf8",$conn);//,"messtest"使用中文编码;
while($rows = mysql_fetch_array($results)){
echo($rows[0]."".$rows[1]."".$rows[2]."".$rows[3]."".$rows[4]);
echo"<br />";
}
//mysql_free_sql($results);
mysql_close($conn);
?>
但是第7行mysql_fetch_array错误,不是有效地实参

第1个回答  2012-10-15
$conn=mysql_connect("localhost","root","1234","messtest");
改为$conn=mysql_connect("localhost","root","1234");

mysql_query($conn,"setnames utf8");
改为mysql_query("setnames utf8",$conn);

mysqli_close($conn);改为mysql_close($conn);

$results->free();//改为mysql_free_result($result);
下个php中文手册 chm版的吧追问

改过之后:$results = $conn->query("SELECT * from gbbook");显示这句有错误?能帮忙吗

追答

你原问题里写的是$results = mysql_query("select * fron gbbook"); // fron 改为 from

$results = $conn->query("SELECT * from gbbook"); //改为
$results = mysql_query("SELECT * from gbbook");
//貌似你把mysql 和 mysqli的用法搞混了。。

参考资料:php中文手册

第2个回答  2012-10-15
顶部加一句 or die(mysql_error());
没有联接成功,需找到原因是啥
empty没用,返回false也能通过empty本回答被网友采纳
第3个回答  2012-10-15
你的用法有问题吧:
mysql_query($conn,"setnames utf8");
mysql_query(sql语句,数据库链接);你用反了
第4个回答  2012-10-15
这样改动一下 //mysql_query($conn,"setnames utf_8");试试

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网