I'm having a heck of time connecting to mySQL. By putting libmysql.dll in the system32 folder I can connect but only as root. If I try to connect as another user I get the following:
Notice: Unable to connect to DBMS: Access denied for user 'user'@'localhost' (using password: YES) in D:\Program Files\Apache Group\Apache2\htdocs\results.php on line 32
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Group\Apache2\htdocs\results.php on line 35
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in D:\Program Files\Apache Group\Apache2\htdocs\results.php on line 35
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in D:\Program Files\Apache Group\Apache2\htdocs\results.php on line 37
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in D:\Program Files\Apache Group\Apache2\htdocs\results.php on line 37
User and pass are correct and I can log in to mysql monitor without a problem. When I connect using root I get nothing returned from my query even though I know there should be a value there. If I run the same query from the MySQL monitor I get a return. Here is my code:
<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
echo 'this is a test1<br />';
// create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm= trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
ini_set('display_errors', 1);
error_reporting(E_ALL);
$db = mysql_pconnect('localhost','user','password');
if(!$db)
{
user_error("Unable to connect to DBMS: " . mysql_error());
}
mysql_select_db('books');
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
echo 'Query '.$query;
echo '<br />';
echo 'Result '.$result;
echo '<br />';
echo phpinfo();
$num_results = mysql_num_rows($result);
echo '<p>Number of books found: '.$num_results.'</p>';
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />ISBN: ';
echo stripslashes($row['isbn']);
echo '<br />Price: ';
echo stripslashes($row['price']);
echo '</p>';
}
?>
this is a test
</body>
</html>
I've enabled mysql and mysqli extensions in php.ini and made sure my PHP install directory is in PATH. Also added extension_dir = "C:\PHP\ext" to php.ini