Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Problem accessing MySQL database (http://www.programmingforums.org/showthread.php?t=8484)

MrMan9879 Feb 19th, 2006 3:28 PM

Problem accessing MySQL database
 
I saw a similar topic to mine, but I couldn't find an answer to help mine. I copied code directly out of the book I'm learning from, but it didn't work. Later, I took the book example out of the CD that it came with, but it didn't work either. Basically, instead of giving me a warning it was just a blank screen except for the header in the <h1> tags. Here is my code:
[PHP]
<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php

// 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;
}

if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}

@ $db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books');

if (mysqli_connect_errno())
{
echo 'Error: Could not connect to database. Please try again later.';
exit;
}

$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);

$num_results = $result->num_rows;

if ($num_results == 0 )
{
echo '<p>No results were found.</p>';
}
else {

echo '<p>Number of books found: '.$num_results.'</p>';

for ($i=0; $i <$num_results; $i++)
{
$row = $result->fetch_assoc();
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>';
}

$result->free();
$db->close();

}
?>
</body>
</html>[/PHP]

I removed the @ on the @ $db, and it did give me an error, and this was it:

Quote:

Fatal error: Class 'mysqli' not found in d:\Apache\Apache\htdocs\results.php on line 27
I am not sure why it doesn't work, and it doesn't make sense to me... since it is right out of the book (and you would think that they woudl have tested their examples...) I figure that it isn't a problem with the setup of the database, because I used the SQL files out of the CD for this example. If someone can tell me why this isn't working, I would greatly appreciate it.

tempest Feb 19th, 2006 4:17 PM

RTFM http://php.net/mysqli

MrMan9879 Feb 19th, 2006 4:45 PM

I checked there already, and I looked again just to be sure... and everything seems to be right in my code. But, I thought this was strange...

Quote:

Predefined Classes
mysqli

Represents a connection between PHP and a MySQL database.
This is what it says for mysqli, but when I run my code, again, this error comes up...

Quote:

Fatal error: Class 'mysqli' not found in d:\Apache\Apache\htdocs\results.php on line 27
It's almost as if the class isn't defined even though it should be.

I checked my php.ini file too, and the php_mysqli.dll extension is turned on.

DaWei Feb 19th, 2006 5:21 PM

Quote:

To install the mysqli extension for PHP, use the --with-mysqli=mysql_config_path/mysql_config configuration option where mysql_config_path represents the location of the mysql_config program that comes with MySQL versions greater than 4.1.
You don't actually say that you did that....

MrMan9879 Feb 19th, 2006 11:25 PM

Well, no... all I did was remove the ; in front of the extension=php_mysqli.dll from the php.ini file.

MrMan9879 Mar 21st, 2006 10:37 PM

I know that this is a fairly old thread, but I am still trying to get this to work! I have since re-installed my server, and I am still getting the same error messages. I took a look in the PHP ext folder, and I realized that there was no PHP_mysqli.dll file... :eek:

I looked in the zip file that the PECL libraries came in, but I don't see the file I need. I have been searching all over the place, but cannot find a place that I can download the php_mysqli.dll file. Does anyone know where I could download it? Or, if you could... e-mail it to

andrewsmythe@shaw.ca.

Ooble Mar 22nd, 2006 1:03 PM

I just downloaded the PHP zip file and it was in there. Tried that?

MrMan9879 Mar 22nd, 2006 7:12 PM

Yay! It's finally working! I can't believe that the only problem was that I was missing the file! That seems like such an obvious thing, I can't believe I didn't notice it!

Infinite Recursion Mar 23rd, 2006 7:54 AM

It's always the simple things that cause the most grief, because you never expect them.

DaWei Mar 23rd, 2006 8:47 AM

Quote:

It's always the simple things that cause the most grief, because you never expect them.
Now you know what pros know: expect 'em.


All times are GMT -5. The time now is 9:25 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC