首页  >  文章  >  后端开发  >  mysqli_connect不报错,但此后操作都显示not a valid MySQL-Link resource

mysqli_connect不报错,但此后操作都显示not a valid MySQL-Link resource

WBOY
WBOY原创
2016-08-04 09:18:581673浏览

<code>$connect = mysqli_connect("host","user","password","db") or die("Error " . mysqli_error($connect));
$result = mysql_query('select * from admin',$connnet);
print(mysql_num_rows($result));
mysql_close();
</code>

报错:

<code>Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
Warning: mysql_close(): no MySQL-Link resource supplied
</code>

而使用面向对象方法则没有问题
请问这是什么问题?

回复内容:

<code>$connect = mysqli_connect("host","user","password","db") or die("Error " . mysqli_error($connect));
$result = mysql_query('select * from admin',$connnet);
print(mysql_num_rows($result));
mysql_close();
</code>

报错:

<code>Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
Warning: mysql_close(): no MySQL-Link resource supplied
</code>

而使用面向对象方法则没有问题
请问这是什么问题?

因为你写错字母了...
第一个变量是 $connect
第二个变量是 $connnect
多了一个n,好不?
当然,也要用mysqli_query而不是mysql_query

mysql_query -> mysqli_query
mysql_num_rows -> mysqli_num_rows
mysql_close -> mysqli_close

哥们你用mysqli_connect创建的连接得用mysqli_xxx来用
mysqli_xxx和mysql_xxx是不能混用的

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn