Home  >  Article  >  Backend Development  >  mysqli_connect does not report an error, but subsequent operations show not a valid MySQL-Link resource.

mysqli_connect does not report an error, but subsequent operations show not a valid MySQL-Link resource.

WBOY
WBOYOriginal
2016-08-04 09:18:581671browse

<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>

Error report:

<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>

There is no problem using the object-oriented method
What is the problem?

Reply content:

<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>

Error report:

<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>

There is no problem using the object-oriented method
What is the problem?

Because you wrote the wrong letters...
The first variable is $connect
The second variable is $connnect
There is an extra n, okay?
Of course, use mysqli_query instead of mysql_query

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

Brother, the connection you create with mysqli_connect must be used with mysqli_xxx
mysqli_xxx and mysql_xxx cannot be mixed

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn