开发者

My project works fine on my local machine, but not on the web server

开发者 https://www.devze.com 2023-01-13 19:40 出处:网络
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:

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()

开发者_StackOverflow中文版

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

";

?>


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
    ";

    ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消