Reputation: 103
I've been told that I was using an deprecated version of PHP, mysql_query, instead of the newer version mysqli_query, and soon it will be remove. Knowing that, I quickly tried to update all of my old, deprecated codes into the newer code. Doing that, I quickly ran into a problem, but I'm not sure what I'm doing wrong. Please take a look:
<?php
$connect = mysqli_connect('server','username','password','database');
$fetch = mysqli_query($connect,"SELECT username FROM userLogin");
while($row=mysqli_fetch_array($fetch,MYSQLI_NUM)){
//do something
}
?>
output:
Warning: mysqli_fetch_array() expects parameter 2 to be long, string given in /home/a2056400/public_html/test4.php on line 8
I have a feeling the error message has something to do with the conditional statement inside the while loop, but I'm not sure what is wrong with it. Please help in any way. Thank you.
Upvotes: 0
Views: 7146
Reputation: 1531
You are not connecting to the database properly.
$connect = mysqli_connect('server','username','password','database');
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$fetch = mysqli_query($connect,"SELECT username FROM userLogin");
while($row=mysqli_fetch_array($fetch,MYSQLI_NUM)) {
//do something
}
Upvotes: 2