I have recently begun to use MySQL on a unix platform using PHP and I am having trouble connecting to the databases. I am able to connect to MySQL OK but get an error message saying the PHP script is unable to access the database. I have tried using very simple scripts and have had expert help on PHP scripts but still no joy. I am beginning to think that the problem lies in MySQL. I have given myself all access rights so this should not be the problem. ANY suggestions would be more than welcome.
The error message is:
Supplied argument is not a valid MySQL result resource in XXXXXX on line XX
The script below is what we have been using.
<?php
$db=mysql_connect("hostname","id","passwd");
mysql_select_db("test");
$sql = "SELECT * FROM employees";
$result=mysql_db_query('dbname', $sql);
$num_of_rows=mysql_num_rows($result);
if ($num_of_rows < 1) {
echo 'no records found!';
exit;
}
for ($i=0; $i<$num_of_rows; $i++) {
$record = @mysql_fetch_object($result);
echo "First name: $record->first".'<BR>';
echo "Last name: $record->last".'<BR>';
echo "Address: $record->address".'<BR>';
echo "Position: $record->position".'<BR>';
}
?>