views:

107

answers:

1

My project is working fine on my local machine but not on the web server. I think it is the stored procedures, because the error that I am getting is:

Fatal error: Call to a member function fetch_array() on a non-object in ...

The collation of the database is "utf8_general_ci".

Just a simple example:

I have a stored procedure called offices:

CREATE PROCEDURE offices()

BEGIN

SELECT * FROM offices;

END//

And the php code:

<?php

require ("db.php");

$db = dbConnect();

$result = $db->query("CALL offices()");

while(list($id, $city, $address) = $result->fetch_array())

echo "($id) $city: $address
";

?>

A: 

I don't think it matters which machine your code is on. This kind of error can occur anywhere.

I do not know much about the interface of your $db->query() method.

Is it returning 'null' upon a 'result error'?

Personally, I would add a bit of error checking between:

  • the call to $db->query() and
  • usage of $result->fetch_array()

ie something along the lines of:

<?php

    require ("db.php");

    $db = dbConnect();

    $result = $db->query("CALL offices()");

    if (!(is_object($result)))
      {
      throw new Exception('No result returned from query: ' . $db->getLatestError() );         
      }

    //count rows
    if ($result->numberOfRows() < 1)
      {
      //do something for no rows
      echo "No Offices found\n";
      return;
      }

    while(list($id, $city, $address) = $result->fetch_array())

    echo "($id) $city: $address
    ";

    ?>
JW
I tried this code "$db->error;" and I got this error "execute command denied to user 'tisegoco_goitse'@'localhost' for routine 'tisegoco_tisego.offices"
mneva
So its a permissions problem. Probably. Is that user set-up and given the appropriate permissions on the second machine?It may be another issue, but I'd check the db users. P.S I'd remove any personal data from your error messages before posting - just for security.
JW
Just want to add that tinkering with privileges/permissions on a remote db is something worth taking time over. There are a few gotchas where sometimes you think you are limiting privileges and in fact open them up more...so don't rush it ;o) http://www.devshed.com/c/a/PHP/Doing-More-With-phpMyAdmin-Part-1/5/...http://dev.mysql.com/doc/refman/5.1/en/adding-users.html ...Hope that didn't sound too patronising!
JW