amyhughes Posted February 2, 2009 Share Posted February 2, 2009 I'm attempting to learn PHP and SQL by reading the book "PHP and MySQL Web Development" by Luke Welling and Laura Thomson. I have PHP 5.2.8, MySQL 5.1 and apache 2.2.11 installed and all seem to be working. The examples in the PHP section of the book seem to work, and working with the database from the command line seems to work. The first use of SQL in a PHP script is causing me trouble. I've reproduced the code below. When I make a query that gets no results it tells me there are no results, so connecting to the database and making the query seem to work. When I make a query that should get one result, apache crashes and gives me the "we're sorry for the inconvenience" bug report dialog. By commenting out code I've narrowed it down to the fetch_assoc() call. After removing that the script tells me there was one result to report. Removing the code in the for-loop the output looks like this (including the query): [pre]Book-O-Rama Search Results query:select * from books where author like '%michael%' Number of books found: 1[/pre] This is the 'books' table: [pre] Table: books Create Table: CREATE TABLE `books` ( `isbn` char(13) NOT NULL, `author` char(50) DEFAULT NULL, `title` char(100) DEFAULT NULL, `price` float(4,2) DEFAULT NULL, PRIMARY KEY (`isbn`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 [/pre] Here's the contents of the table: [pre]*************************** 1. row *************************** isbn: 0-672-31509-2 author: Pruitt, et al. title: Teach Yourself GIMP in 24 Hours price: 24.99 *************************** 2. row *************************** isbn: 0-672-31697-8 author: Michael Morgan title: Java 2 for Professional Developers price: 34.99 *************************** 3. row *************************** isbn: 0-672-31745-1 author: Thomas Down title: Installing Debian GNU/Linux price: 24.99 *************************** 4. row *************************** isbn: 0-672-31769-9 author: Thomas Schenk title: Caldera OpenLinux System Administration Unleashed price: 49.99 4 rows in set (0.02 sec) [/pre] Here's the code: [pre]<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=trim($_POST['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); echo "<p>query:$query</p>"; $num_results = $result->num_rows; 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>[/pre] Any clue why apache is crashing on fetch_assoc()? Thanks, Amy Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 2, 2009 Author Share Posted February 2, 2009 Here's what the apache error log tells me: [Mon Feb 02 16:41:00 2009] [notice] Parent: child process exited with status 3221225477 -- Restarting. It then restarts. Doing a little googling, I see suggested that I read this page... http://mirrors.axint.net/apache/httpd/binaries/win32/README.html which suggests adding this to my httpd.conf file for maximum Windows compatibility: EnableSendfile Off EnableMMAP Off Win32DisableAcceptEx But that doesn't change anything. Still crashes. Yes, I restarted apache. Quote Link to comment Share on other sites More sharing options...
trq Posted February 2, 2009 Share Posted February 2, 2009 Place this at the top of your script. <?php error_reporting(E_ALL) ; ini_set('display_errors',1); ?> Are you getting any errors? Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 2, 2009 Author Share Posted February 2, 2009 Place this at the top of your script. <?php error_reporting(E_ALL) ; ini_set('display_errors',1); ?> Are you getting any errors? Not that I can tell. With that at the top of my script I get no additional output when the fetch_assoc() is removed from the code, and with fetch_assoc() in the code I get no output at all. The errors would show in the page source, right? Thanks, AMy Quote Link to comment Share on other sites More sharing options...
corbin Posted February 2, 2009 Share Posted February 2, 2009 Hrmmm..... Sounds to me like a corrupted php_mysql.dll or php.exe. I would guess a corrupted php_mysql.dll. There could be other issues too, but that is the most likely. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 2, 2009 Author Share Posted February 2, 2009 Hrmmm..... Sounds to me like a corrupted php_mysql.dll or php.exe. I would guess a corrupted php_mysql.dll. There could be other issues too, but that is the most likely. I just downloaded another copy from another mirror and the checksum for php.exe, php_mysql.dll and php_mysqli.dll are the same. BTW, the installation instructions in the book say to un-comment php_mysqli.dll in php.ini but say nothing about php_mysql.dll. So, just now I tried reversing those, and I got an error on the mysqli call. Tried un-commenting both and got the apache crash. So, I'm back to php_mysqli.dll. Also FWIW I'm using php 5.2.8 and PECL 5.2.6, because the php download instructions say there isn't going to be a PECL 5.2.8 and that 5.2.6 will work with php 5.2.8. That's not a problem, is it? Quote Link to comment Share on other sites More sharing options...
corbin Posted February 2, 2009 Share Posted February 2, 2009 The PECL thing shouldn't matter. php_mysqli contains the mysqli_* functions, and php_mysqli contains the mysql_* functions ;p. I wonder if the client library for MySQL is screwed up or something.... It has to be a messed up file somewhere. I don't know what else it would be, since a fetch_assoc call shouldn't be causing Apache to crash. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 1. Is downgrading php and/or apache a reasonable thing to try? 2. Is there a way to get the results of the query without using fetch_assoc? I tried the "procedural style" example here... http://us.php.net/MySQLi_Result::fetch_assoc with the same results. Grasping at straws now. Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 1. You could try it. 2. fetch_row or fetch_array, but you should fix the problem, not avoid it. Hrmmmm, I must think something is corrupted as I don't know what else could cause this problem. Does it do it with any query? I'm guessing yes. Also, try enabling php_mysql.dll and seeing if mysql_fetch_assoc does it. Edit: Just checked and they both load libmysql.dll, so perhaps that is corrupted some how. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 1. I downgraded to apache 2.2.9 and php 5.2.6. These are the versions that came with the book. This did not solve the problem. 2. I simplified the query. If I select only one column it does not crash. If I select more than one (it doesn't matter which ones) it crashes. Here's a script that does not crash, taken pretty much directly from the php manual: <html> <head> <title>Book-O-Rama Search Results</title> </head> <body> <h1>Book-O-Rama Search Results</h1> <?php error_reporting(E_ALL) ; ini_set('display_errors',1); $link = mysqli_connect("localhost", "bookorama", "bookorama123", "books"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT title FROM books"; if ($result = mysqli_query($link, $query)) { /* fetch associative array */ while ($row = mysqli_fetch_assoc($result)) { printf ("<p>%s</p>\n", $row["title"]); } /* free result set */ mysqli_free_result($result); } /* close connection */ mysqli_close($link); ?> </body> </html> Here's one that does crash. It differs from the above only by the columns that are selected: <html> <head> <title>Book-O-Rama Search Results</title> </head> <body> <h1>Book-O-Rama Search Results</h1> <?php error_reporting(E_ALL) ; ini_set('display_errors',1); $link = mysqli_connect("localhost", "bookorama", "bookorama123", "books"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $query = "SELECT author, title FROM books"; if ($result = mysqli_query($link, $query)) { /* fetch associative array */ while ($row = mysqli_fetch_assoc($result)) { printf ("<p>%s</p>\n", $row["title"]); } /* free result set */ mysqli_free_result($result); } /* close connection */ mysqli_close($link); ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 Also, try enabling php_mysql.dll and seeing if mysql_fetch_assoc does it. It crashes. Just checked and they both load libmysql.dll, so perhaps that is corrupted some how. Unless both 5.2.8 that I downloaded and 5.2.6 that I installed from CDROM are bad, I think this is not a promising avenue to explore. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 Just checked and they both load libmysql.dll, so perhaps that is corrupted some how. Curious. I have one in my php directory (c:/php) and one with my mysql installation (c:/Program Files/MySQL/MySQL Server 5.1/bin), and they don't look like they are the same version (they aren't the same size or date). I'm guessing the one in the php directory is 5.0.something. Which am I using when I make calls from a php script? I installed MySQL as a service a few days ago, before I started working with php. Should I downgrade MySQL? Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 Hrmmm... Try renaming the one in C:\PHP libmysql2.dll or something, and copy the one from your MySQL bin to C:\PHP. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 Hrmmm... Try renaming the one in C:\PHP libmysql2.dll or something, and copy the one from your MySQL bin to C:\PHP. Crash I offer as reason for my next downgrade the last comment in this thread: http://bugs.php.net/bug.php?id=44645 Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 [2 Aug 2008 7:53pm UTC] pajoye@php.net "I fix this bug renaming the libmysql.dll in C:\Program Files\MySQL\MySQL Server 5.1\bin to libmysql.dll_ Now php uses libmysql.dll in c:\php directory and phpinfo shows Client Api version 5.0.19. Before showed 5.1.25rc" Ah that is definitively a good thing to do, using 5.1 DLLs with PHP binaries is wrong. About the backtrace, it seems that you are missing the debug pack, I can't see any symbols ( Error WARNING - DebugDiag was not able to locate debug symbols for php5ts.dll, so the information below may be incomplete.). Hrmmm, before you go and downgrade everything, you could give that a go since it would take about 2 seconds to test. Based on that bug report, it would seem that libmysql.dll and x64 don't get along. You could try finding a x64 version of MySQL and using the libmysql out of its bin. (By the way, are you running a 64 bit OS? Because if not, ignore the last thing I just said about finding a x64 version ;p.) Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 I do not have a 64-bit OS. This is WinXp Pro SP3 (32-bit version). I did downgrade MySQL, and now it won't let me back into my database. I'd really like to just blow it away and start over. Edit: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) I told it not to modify my security settings. Edit2: Apparently it did blow away the old database. Root did not have a password, so trying to log in with one failed. Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 What version did you down grade to? I think that solution might have been worth trying even if you're on a 32x OS, by the way. Someone in the bug report said it worked for him and he had a x32 OS. I'm almost positive now that the problem involves libmysql, but I don't know what version of libmysql you need. I guess it would depend on PHP. Odd though that it would have the wrong version bundled with it, so maybe that's not it. Did you downgrade to MySQL 4 from 5? MySQL 4 and 5 use different password hashing methods, so your password is probably being hashed entirely differently now.... x.x. There are ways to make MySQL4 passwords work with MySQL5, but I don't know about the opposite. You can start MySQL without permissions though and just reset your password (mysqld.exe in the MySQL bin dir.... You'll need to read the help to see which command does it). If you're super determined you could generate a debug backtrace. That way you would know exactly what block of code in either the PHP core or php_mysqli (or one of the DLLs it imports) is causing the crash. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 I now have php 5.2.6, apache 2.2.9 and mysql 5.0.67. I have a root account with a password and I'm able to login. I can create a user account without any errors, but when I try to log in to that user account I get ERROR 1045 (28000): Access denied for user 'bookorama'@'localhost' (using password: YES) This has turned into a MySQL problem. Before I can resume testing on the original php problem I must solve this MySQL problem. But I've had about enough. Thanks for your help. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 Got the downgraded database working. fetch_assoc() still crashes apache. Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 Just of curiosity, did you use an installer to install PHP? (Like did you run an exe that had Next buttons and so on.) Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 Just of curiosity, did you use an installer to install PHP? (Like did you run an exe that had Next buttons and so on.) No, it was un-zipped. When I down-graded, I deleted the php folder and un-zipped the older files, edited php.ini again, restarted apache. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 If you're super determined you could generate a debug backtrace. That way you would know exactly what block of code in either the PHP core or php_mysqli (or one of the DLLs it imports) is causing the crash. > php_mysqli.dll!01572beb() php_mysqli.dll!01571582() php5ts.dll!0078a023() php_mysqli.dll!01578d97() php5ts.dll!0079cdf9() php5ts.dll!007a30b5() php5ts.dll!0079c595() php5ts.dll!008292a4() php5ts.dll!00782e87() php5ts.dll!0083e14d() ntdll.dll!7c9101bb() ntdll.dll!7c9114b6() ntdll.dll!7c9114f4() ntdll.dll!7c9114ca() ntdll.dll!7c90d07c() kernel32.dll!7c80a77a() kernel32.dll!7c80a79e() kernel32.dll!7c83089d() ntdll.dll!7c9115a6() ntdll.dll!7c9115a6() kernel32.dll!7c8308bf() libmySQL.dll!01366980() libmySQL.dll!01364859() libmySQL.dll!0136480f() php_mysqli.dll!01572545() php5ts.dll!00787a7d() php5ts.dll!0081c800() php5ts.dll!0083dfe3() php5apache2_2.dll!100034fd() libapr-1.dll!6eed198a() php5apache2_2.dll!10003271() mod_mime.so!6fc21a40() php5ts.dll!0083bfd0() libhttpd.dll!6ff020e1() libhttpd.dll!6ff0246e() libhttpd.dll!6ff0e90e() libhttpd.dll!6ff0a87c() libhttpd.dll!6ff04d21() libhttpd.dll!6ff04fd3() libhttpd.dll!6ff1d2dc() msvcrt.dll!77c3a3b0() ntdll.dll!7c91a5de() kernel32.dll!7c80b713() ntdll.dll!7c91a5de() Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 Hrmmm that looks like it's just a list of function calls by addresses in DLLs.... Is there anything more detailed? Try getting the debug pack. Hrmmm.... I'm going to download PHP 5.2.6 and see if I get the same problem. I doubt I will though. Quote Link to comment Share on other sites More sharing options...
amyhughes Posted February 3, 2009 Author Share Posted February 3, 2009 Hrmmm that looks like it's just a list of function calls by addresses in DLLs.... Is there anything more detailed? Try getting the debug pack. I don't know where to get that, and I'm reluctant to download it from just anywhere. And building it from source is beyond the scope of reasonable, and probably fraught with failure, anyway. Hrmmm.... I'm going to download PHP 5.2.6 and see if I get the same problem. I doubt I will though. Highly unlikely, and please don't break anything on my account. Quote Link to comment Share on other sites More sharing options...
corbin Posted February 3, 2009 Share Posted February 3, 2009 http://us2.php.net/get/php-debug-pack-5.2.6-nts-Win32.zip/from/a/mirror I wonder.... What is your PATH? (Open CMD and type "echo %PATH%") I'm curious where PHP is loading libmysql from. ....please don't break anything on my account. Huh??? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.