SkilletZA Posted August 25, 2013 Share Posted August 25, 2013 Hi Guys Noob here. Trying to browse MySql data through PHP script but getting this error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\browse.php on line 8 This is the piece of code causing this: <?php $connect = mysqli_connect("192.168.0.3","demo","demo"); mysql_select_db("my_db"); $query = mysql_query("SELECT * FROM persons WHERE Age = '28' "); WHILE($rows = mysql_fetch_array($query)): $FirstName = $rows['FirstName']; $LastName = $rows['LastName']; $Age = $rows['Age']; echo "$FirstName $LastName $Age"; endwhile; ?> Pleas help! Link to comment https://forums.phpfreaks.com/topic/281546-help-on-error-mysql_fetch_array-expects-parameter-1-to-be-resource/ Share on other sites More sharing options...
jazzman1 Posted August 25, 2013 Share Posted August 25, 2013 You are mixing two different mysql libraries in php. Link to comment https://forums.phpfreaks.com/topic/281546-help-on-error-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1446696 Share on other sites More sharing options...
0xMatt Posted August 25, 2013 Share Posted August 25, 2013 He may not even understand what you mean by that since he's a self-proclaimed noob. What jazzman1 is saying is that you are using mysqli_connect() to establish a database connection and you are using mysql_ functions for everything else. mysqli_connect() is actually just an alias for the mysqli extension constructor and is all you need to make a db connection, you just need to define the database table inside the parameters like so: $link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db'); Like I said, mysqli_connect() is just an alias so people can use the procedural method which isn't recommended these days. Instead I'd use something like this: <?php $mysqli = new mysqli('192.168.0.3', 'demo', 'demo', 'my_db'); $result = $mysqli->query("SELECT * FROM persons WHERE Age = '28'"); while($rows = $result->fetch_assoc()) { $FirstName = $rows['FirstName']; $LastName = $rows['LastName']; $Age = $rows['Age']; echo "$FirstName $LastName $Age"; } Remember that you cannot use mysql_ functions with mysqli_functions. Link to comment https://forums.phpfreaks.com/topic/281546-help-on-error-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1446698 Share on other sites More sharing options...
SkilletZA Posted August 25, 2013 Author Share Posted August 25, 2013 What an awesome forum!! Thanks for the VERY quick assistance guys! Link to comment https://forums.phpfreaks.com/topic/281546-help-on-error-mysql_fetch_array-expects-parameter-1-to-be-resource/#findComment-1446699 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.