www.webdeveloper.com
Results 1 to 4 of 4

Thread: mysqli queries

  1. #1
    Join Date
    Mar 2009
    Posts
    6

    mysqli queries

    I have a baffling problem trying to query a MySQL database using mysqli. I can only use the fetch_row method - the fetch_assoc doesn't work.

    I don't think it's relevant but the code fragments below are called from a singleton DBManager class within a try{} block.

    So this works fine.....
    $result = $this->_dbConnection->query('SELECT name, shortname FROM real_club');
    while ($row = $result->fetch_row())
    printf ('%s %s<br>', $row[0], $row[1]);


    But calling any of the other fetch functions (e.g. fetch_assoc) doesn't work, whether calling them procedurally or using the class interface. (NB $result->fetch_array(MYSQLI_NUM) is OK too.

    So if I replace the fetch in the above code with the following
    while ($row2 = $result->fetch_assoc())
    echo "hello world<br>";

    Then I end up with a Page Load Error - "Network Timeout - The operation timed out when attempting to contact www.localhost.com"


    I can get by with the fetch_row, but would prefer to use fetch_assoc.
    $finfo = $result->fetch_fields() works completely as expected, so I think the DB is working as I'd expect it to. Fields returned by it are as follows:
    Table: real_club
    Name: name
    Flags: 4097
    Type: 253

    Table: real_club
    Name: shortname
    Flags: 4097
    Type: 253

    I am using php 5.2.8, MySql 5.1.31.

    Any ideas would be appreciated. It seems like a very strange way for the call to fail.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,326
    I don't know of any reason why fetch_row() should work but not fetch_assoc(). All I can think of without more info to go by is that the client mysql programs (e.g. the DLLs if a Windows installation) are somehow corrupt or missing. You might want to try to find the smallest, simplest piece of code that will replicate the error and post it here to see if we can detect anything "odd" about it -- or doing so might help you find the problem yourself. (Be sure to turn on all error_reporting.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2009
    Posts
    6

    more info...

    Thanks for the suggestion.

    This file replicates the problem. Set $fetchRow = true and it works exactly as expected. Set $fetchRow to false and the Network Timeout error appears.
    NB To run the program I type localhost/sqli_issue.php into the browser. When I get the problem the URL becomes 'http://www.localhost.com/sqli_bug.php' after the timeout (about 30s).

    I am running on Vista...

    Here's the simple file.

    <?php
    $conn = mysqli_connect('localhost', 'root', 'passwd', 'mytestdb');
    $result = $conn->query('SELECT name, shortname FROM real_club');

    $fetchRow = true;

    if ($fetchRow)
    {
    echo '---fetch_row---<br>';
    while ($row = $result->fetch_row())
    printf ('%s %s<br>', $row[0], $row[1]);
    }
    else
    {
    echo '---fetch_assoc---<br>';
    while ($row2 = $result->fetch_assoc())
    echo 'row2<br>';
    }
    ?>

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,326
    Ran OK for me locally (I only changed the DB login credentials, database name, and table/column names to match an existing DB). I'm running PHP 5.2.9, MySQL 5.1.32, Apache 2.2.11 on Windows Vista.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles