-1

I created a very simple database on mySQL using phpMyAdmin. Now I want to connect my database through php file so that I can manipulate data in DB, i.e. inserting, deleting, showing, updating data. I wrote the code:

index.php file:

    <?php
include 'includes/connection.php';
$query="SELECT * FROM people";
$result=mysql_query($query);
while($person= mysql_fetch_array($result)){
echo "<h3>". $person['name']."</h3>";

}
?>

connection.php file:

    <?php
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$db='mysql_tut';
$conn=mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($db);

?>

But it shows the following error in the browser window:

 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\phpMyAdmin\index.php on line 5
  • Likely, `$resource` is `FALSE` because `mysql_query` returned an error. Normative pattern is to test whether mysql_query function suceeded. The conditional test is as simple as `if (!$resource)`. Simplest action to take would be `die(mysql_error());`, though this isn't necessarily the most appropriate action. BTW... new development should use the **mysqli** or **PDO** interface, not the deprecated mysql interface. – spencer7593 Aug 24 '14 at 01:00

1 Answers1

0

You gotta pass two parameters to the function. The database name and the query.

$conn = mysqli_connect($query, $query);

I use mysqli_connect instead of mysql_connect becaouse mysql is deprecated.

mishelashala
  • 413
  • 2
  • 5
  • 12