Hello all, I am brand new to PHP, MySQL and Apache but I have over 25 years of software development experience on other platforms and more than 15 years of client/server, object-oriented, GUI, and SQL back-end development experience, so I feel confident that I will be able to give back to this community within the near future.

Anyways, hopefully someone can help me. Actually, I've made a lot of progress already. I've got PHP, MySQL and Apache installed and everything seems to be working to some extent. Through PHP, I can connect to my database and do a query and I get back rows when I use fetch_row. The problem is that when I use fetch_assoc or fetch_object, the system churns and churns and then finally comes back with a connection interruption error.

My code looks okay to me. I copied from php.net and the Welling and Thomson book. Here is my test code:

<?php
$mysqli = new mysqli("localhost", "bookorama", "bookorama123", "books");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
else {
	echo "<p>I'm in.</p>";
}
 
$query = "SELECT title, isbn from books";

if ($result = $mysqli->query($query)) {

	echo "<p>query is ok.</p>";

    /* fetch assoc array 
    while ($row = $result->fetch_assoc()) {
	    echo "<p><strong>Title:  ";
        echo htmlspecialchars(stripslashes ($row['title']));
        echo "<br />ISBN:  ";
        echo stripslashes($row['isbn']);
    }
	*/
	
    /* fetch object array 
    while ($obj = $result->fetch_object()) {
        echo "<p>$obj->title, $obj->isbn</p>";
    }
	*/
	    
    /* fetch row array */
    while ($row = $result->fetch_row()) {
        echo "<p>$row[0], $row[1])</p>";
    }
    
    
    /* free result set */
    $result->close();
}

/* close connection */
$mysqli->close();
?>

Since I am expecting this to be a configuration problem, I am attaching my php.ini, http.conf and phpinfo output.

Thanks in advance if you can help me.

Welcome jacobus8.

Please post your code in BB Tag. I think You have a problem with installation.

Welcome jacobus8.

Please post your code in BB Tag. I think You have a problem with installation.

Hello, and thank you for responding. I was completely unfamiliar with this term "BB Tag", but I looked it up just now and found this link: http://www.sitepoint.com/print/bb-code-php-application/

Do I need to install PEAR and BBParser and study a tutorial like this and then re-submit my code, reformatted with these BB Tags? Or is there something more straightforward that I could do?

Perhaps you already have a clue what the installation issue might be? Let's assume for a moment that the code is okay. What would you suggest that I do?

I do appreciate your help very much.

Hello, and thank you for responding. I was completely unfamiliar with this term "BB Tag", but I looked it up just now and found this link: http://www.sitepoint.com/print/bb-code-php-application/

Do I need to install PEAR and BBParser and study a tutorial like this and then re-submit my code, reformatted with these BB Tags? Or is there something more straightforward that I could do?

Perhaps you already have a clue what the installation issue might be? Let's assume for a moment that the code is okay. What would you suggest that I do?

I do appreciate your help very much.

Dude, all he meant was that when you submit code into the forum, just wrap it around with code tags (they look like this: square_brace code square_brace code in here square_brace / code square_brace). They will make sure that the forum displays the stuff with syntax coloring and all that...

Dude, all he meant was that when you submit code into the forum, just wrap it around with code tags (they look like this: square_brace code square_brace code in here square_brace / code square_brace). They will make sure that the forum displays the stuff with syntax coloring and all that...

Okay, great! Thanks. I was thinking and hoping that he meant something simple like that.

Okay, so here it is with the BB tags:

<?php
$mysqli = new mysqli("localhost", "bookorama", "bookorama123", "books");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else {
echo "<p>I'm in.</p>";
}

$query = "SELECT title, isbn from books";

if ($result = $mysqli->query($query)) {

echo "<p>query is ok.</p>";

/* fetch assoc array
while ($row = $result->fetch_assoc()) {
echo "<p><strong>Title: ";
echo htmlspecialchars(stripslashes ($row['title']));
echo "<br />ISBN: ";
echo stripslashes($row['isbn']);
}
*/

/* fetch object array
while ($obj = $result->fetch_object()) {
echo "<p>$obj->title, $obj->isbn</p>";
}
*/

/* fetch row array */
while ($row = $result->fetch_row()) {
echo "<p>$row[0], $row[1])</p>";
}


/* free result set */
$result->close();
}

/* close connection */
$mysqli->close();
?>

Thanks again.

Ok.

So mysqli_result::fetch_row works perfectly, but mysqli_result::fetch_assoc and mysqli_result::fetch_object on the same instance cause PHP to freeze?

I very much doubt that would have anything to do with your code. (Unless it involves some shady loops, which I don't see in your code).
So my guess is that either your mysqli extension, or your PHP installation is somehow bad or corrupt.

I would try downloading the zip package from PHP download page and replace the ext/php_mysqli.dll file under your PHP installation directory.

If that doesn't work, try to simply replace the entire installation with the one from the ZIP package. Swapping the old directory with the one from the ZIP package should work. (Make sure you preserve your php.ini tho, if it is in there.)

See what that does.

Ok.

So mysqli_result::fetch_row works perfectly, but mysqli_result::fetch_assoc and mysqli_result::fetch_object on the same instance cause PHP to freeze?

I very much doubt that would have anything to do with your code. (Unless it involves some shady loops, which I don't see in your code).
So my guess is that either your mysqli extension, or your PHP installation is somehow bad or corrupt.

I would try downloading the zip package from PHP download page and replace the ext/php_mysqli.dll file under your PHP installation directory.

If that doesn't work, try to simply replace the entire installation with the one from the ZIP package. Swapping the old directory with the one from the ZIP package should work. (Make sure you preserve your php.ini tho, if it is in there.)

See what that does.

Hello Atli, thank you for your response. Your suggestions made a lot of sense and I tried both suggestions, but unfortunately no cigar yet.

Further I have simplified my test script, partially to address what you correctly pointed out -- there was a remote possibility that there was a looping issue. Secondly, I wanted to take up just one of these functions at a time -- fetch_assoc. Once I solve the issue for fetch_assoc(), if I'm still having trouble with fetch_object(), we'll take that up separately.

So, now with this new script, I get a network timeout, but if I comment out the call to fetch_assoc() at line 19, I get what I expect:

I'm in.

query is ok.

So here is the new code:

<?php
$mysqli = new mysqli("localhost", "bookorama", "bookorama123", "books");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
else {
	echo "<p>I'm in.</p>";
}
 
$query = "SELECT title, isbn from books";

if ($result = $mysqli->query($query)) {

	echo "<p>query is ok.</p>";

    $row = $result->fetch_assoc();    // fetch assoc array one time only
    if ($mysqli->errno) {
	   	echo "fetch error: ".$mysqli->error;
	}
	
    /* free result set */
    $result->close();
}

/* close connection */
$mysqli->close();
?>

What about MySQL configuration files? Should I look for potential issues there?

I appreciate your suggestions.

Will you show us a database table structure?

Will you show us a database table structure?

Yes, of course. In my test script I am only referencing the books table which looks like this:

CREATE TABLE books
( isbn char(13) not null primary key,
  author char(50),
  title char(100),
  price float(4,2)
);

Currently there are only 4 rows in this books table. When I use mysqli_result::fetch_row() , the 4 rows come back very quickly, of course. Also, I'm not sure if you noticed or not, but I just sent a response to Atli which included a streamlined test script which should be much easier for us to work from. When I comment out the one line which calls mysqli_result::fetch_assoc() , the script works perfectly.

Please let me know if you'd like more information.

Thanks for responding.

Had to read this thread? http://bugs.php.net/bug.php?id=48453

I think your problem is due to mysql database. I read about mysql version 5.x had bugs but I am not sure.

Oh, very good! And now that you have pointed me in the direction, I find this one also, found in MS SQL: http://bugs.php.net/bug.php?id=18622

Apparently, this bug has been coming up in PHP off and on for years, and not only with MySQL.

Well, I guess, within the limits of what DaniWeb can do, the thread is solved as far as this forum is concerned.

I will add a comment to this bug on php.net.

Thank you so much.

Thanks, Greate! I appreciate your comment.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.