在非对象错误上调用成员函数bind_param(),但是SQL工作。

时间:2022-01-23 20:35:46

I have an SQL query that run successfully in phpmyadmin, but in PHP it invoke Call to a member function bind_param() on a non-object error message. Can you give any ideas what can be wrong?

我有一个在phpmyadmin中成功运行的SQL查询,但是在PHP中,它调用一个非对象错误消息中的成员函数bind_param()。你能告诉我什么是错误的吗?

$con = mysqli_connect($mysql_server,$mysql_user,$mysql_pass,$mysql_database);
    if (!$con)
        {
          $error_auth="Failed to connect to MySQL: " . mysqli_connect_error();
          return false;
        };

    $stmt = $con->prepare("SELECT `start`, `timetable`.`id`, `guide_id`, `name`  FROM `timetable` INNER JOIN `excursions` ON `timetable`.`excursion_id` = `excursions`.`id` WHERE `name` LIKE ?  LIMIT 150");
    if (!$stmt)
    {
         echo "Errormessage: %s\n";
         echo $mysqli->error;
    }
    //, $from_date,  $to_date
    $stmt->bind_param("s",  "%".$str_search."%");

And error:

和错误:

Errormessage: %s
<!--error--><br />
<b>Fatal error</b>:  Call to a member function bind_param() on a non-object in <b>\json\classes\tigran_search_transaction_script.php</b> on line <b>27</b><br />

1 个解决方案

#1


2  

The error is your 'bind_param' statement:

错误是您的“bind_param”语句:

'bind_param' expect a variable that it can take the 'reference' of. You pass a 'calculated' value. Sadly, only PHP knows where that is stored and it will not tell anyone about where it lives.

“bind_param”期望一个变量,它可以引用“引用”。你传递一个“计算”值。遗憾的是,只有PHP知道存储在哪里,它不会告诉任何人它的位置。

what you need to do is:

你需要做的是:

$my_str_search = "%".$str_search."%";

$stmt->bind_param("s",  $my_str_search);

All will be well as PHP can now tell the database exactly where to look get all the information, in the correct format, that it needs.

PHP现在可以准确地告诉数据库哪里可以获得所需的所有信息。

#1


2  

The error is your 'bind_param' statement:

错误是您的“bind_param”语句:

'bind_param' expect a variable that it can take the 'reference' of. You pass a 'calculated' value. Sadly, only PHP knows where that is stored and it will not tell anyone about where it lives.

“bind_param”期望一个变量,它可以引用“引用”。你传递一个“计算”值。遗憾的是,只有PHP知道存储在哪里,它不会告诉任何人它的位置。

what you need to do is:

你需要做的是:

$my_str_search = "%".$str_search."%";

$stmt->bind_param("s",  $my_str_search);

All will be well as PHP can now tell the database exactly where to look get all the information, in the correct format, that it needs.

PHP现在可以准确地告诉数据库哪里可以获得所需的所有信息。