Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 19th, 2006, 3:28 PM   #1
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
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.
MrMan9879 is offline   Reply With Quote
Old Feb 19th, 2006, 4:17 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
RTFM http://php.net/mysqli
__________________

tempest is offline   Reply With Quote
Old Feb 19th, 2006, 4:45 PM   #3
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
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.
MrMan9879 is offline   Reply With Quote
Old Feb 19th, 2006, 5:21 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 19th, 2006, 11:25 PM   #5
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
Well, no... all I did was remove the ; in front of the extension=php_mysqli.dll from the php.ini file.
MrMan9879 is offline   Reply With Quote
Old Mar 21st, 2006, 10:37 PM   #6
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
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.
MrMan9879 is offline   Reply With Quote
Old Mar 22nd, 2006, 1:03 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I just downloaded the PHP zip file and it was in there. Tried that?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 22nd, 2006, 7:12 PM   #8
MrMan9879
Programmer
 
MrMan9879's Avatar
 
Join Date: Sep 2005
Location: Nanaimo, BC, Canada
Posts: 97
Rep Power: 0 MrMan9879 is an unknown quantity at this point
Send a message via MSN to MrMan9879
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!
MrMan9879 is offline   Reply With Quote
Old Mar 23rd, 2006, 7:54 AM   #9
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
It's always the simple things that cause the most grief, because you never expect them.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Mar 23rd, 2006, 8:47 AM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:46 AM.

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