![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Programmer
|
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:
|
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
__________________
|
|
|
|
|
|
#3 | ||
|
Programmer
|
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:
Quote:
I checked my php.ini file too, and the php_mysqli.dll extension is turned on. |
||
|
|
|
|
|
#4 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
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 |
|
|
|
|
|
|
#5 |
|
Programmer
|
Well, no... all I did was remove the ; in front of the extension=php_mysqli.dll from the php.ini file.
|
|
|
|
|
|
#6 |
|
Programmer
|
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. |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I just downloaded the PHP zip file and it was in there. Tried that?
|
|
|
|
|
|
#8 |
|
Programmer
|
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!
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#10 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
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 |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|