0

I have mysqli script, Unfortunately it doesn't run on my Server with PHP 5.3.29.

As far as I can debug the server doesn't return any value for the function get_result() and the script breaks after it. Is there any know issue?

$query = "SELECT * FROM test WHERE column = ? LIMIT 1";

    $stmt = $mysqli->stmt_init();

    if(!$stmt->prepare($query)) echo "Failed to prepare statement\n";
    else echo "prepare statement okay\n";

    if(!$stmt->bind_param('s', 'test')) echo "Failed to bind parameter\n";
    else echo "bind parameter okay\n";

    if(!$stmt->execute()) echo "Failed to execute\n";
    else echo "execute okay\n";

    $result = $stmt->get_result();

    if(!$result) echo "Failed to get result \n";
    else echo "result okay\n";

The output would be just:

prepare statement okay
bind parameter okay
execute okay

Any ideas?

hakre
  • 178,314
  • 47
  • 389
  • 754
wittich
  • 1,661
  • 1
  • 18
  • 37
  • Have you tried to return any value from `mysqli->error` ? And what is `stmt_init()` for? – Martin Mar 20 '15 at 18:04
  • reading up about `stmt_init` you would need to prepend all your following actions with `stmt_` such as `->stmt_prepare` instead of just `->prepare` . I think you should be able to work well enough with that initial `stmt_init`. – Martin Mar 20 '15 at 18:06
  • okay just install 5.3.29 local too, same issue but now I can check the logs ;-) – wittich Mar 20 '15 at 18:28
  • 1
    I get the message `PHP Fatal error: Call to undefined method mysqli_stmt::get_result()`. Thx @Martin I'll check now your hint... – wittich Mar 20 '15 at 18:31
  • @Martin `PHP Fatal error: Call to undefined method mysqli_stmt::stmt_prepare()` – wittich Mar 20 '15 at 18:33
  • try it this time ignoring all the `stmt_` functions. I never use them on my MySQLi . – Martin Mar 20 '15 at 18:41
  • @Martin I don't get what you mean. I think the problem is with [mysqli_stmt::get_result](http://php.net/manual/en/mysqli-stmt.get-result.php) though it says its available since PHP 5 >= 5.3.0. – wittich Mar 20 '15 at 18:58
  • If it says that, well your version of PHP is 5.3.29 so your version supersedes 5.3.0 . As I said, I don't think you have much need to use the `_stmt` family of MySQLi functions. – Martin Mar 20 '15 at 19:00
  • Okay, I just liked the way of prepare and bind parameter. I'll check the capability of MySQLi further... By the way I think I found the answer why get_result() is not defined: http://stackoverflow.com/questions/8321096/call-to-undefined-method-mysqli-stmtget-result – wittich Mar 20 '15 at 19:04
  • You can still prepare and bind without `_stmt` it's the new standard MySQLi method. – Martin Mar 20 '15 at 19:05
  • 2
    (from reading the link) ahh you need a driver .... – Martin Mar 20 '15 at 19:05
  • would be much easier to debug with PDO in PDO::ERRMODE_EXCEPTION :p – hanshenrik Mar 20 '15 at 23:50

1 Answers1

1

You are getting the following error:

PHP Fatal error: Call to undefined method mysqli_stmt::get_result()

The error message does not leave any room for doubt: You're calling a method that does not exists.

Looking up the method in question in the PHP manual shows this detail:

Available only with mysqlnd.

So it's not only the PHP version you need to fulfil but also a specific mysql driver.

hakre
  • 178,314
  • 47
  • 389
  • 754