未定义 属性:mysqli_stmt::$bind_param
Undefined property: mysqli_stmt::$bind_param
我想用call_user_func_array
这样绑定变量号参数(请阅读代码处的注释):
function dbQuery()
{
global $dbconnection;
if (func_num_args() < 1 || func_num_args() === 2) {
return error('خطای داخلی');
} else if (func_num_args() === 1) {
$stmt = $dbconnection->prepare(func_get_arg(0)); // Creating stmt
if (!$stmt) {
return error('خطای پایگاه داده');
}
if (!$stmt->execute()) {
return error('خطا در تعامل با پایگاه داده');
}
return $stmt;
} else {
$args = func_get_args();
$stmt = $dbconnection->prepare($args[0]); // args[0] is the query with question marks
if (!$stmt) {
return error('خطای پایگاه داده');
}
array_shift($args);
foreach ($args as $index => $arg) {
${'arg' . $index} = $dbconnection->real_escape_string($arg); // making args as variables because bind_params does not allow direct values
$args[$index] = ${'arg' . $index};
}
if (!call_user_func_array($stmt->bind_param,$args)) { // ERROR IS HERE LINE 67
return error('خطای امنیتی پایگاه داده');
}
if (!$stmt->execute()) {
return error('خطا در تعامل با پایگاه داده');
}
return $stmt;
}
}
$stmt = dbQuery('SELECT * FROM payments WHERE id=?','i',31);
$result = dbCheck($stmt);
var_dump($result->fetch_all());
错误是:
PHP Warning: Undefined property: mysqli_stmt::$bind_param in /home/mwxgaf/w/projects/foodorder/test.php on line 67
PHP Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be a valid callback, no array or string given in /home/mwxgaf/w/projects/foodorder/test.php:67
Stack trace:
#0 /home/mwxgaf/w/projects/foodorder/test.php(76): dbQuery()
#1 {main}
thrown in /home/mwxgaf/w/projects/foodorder/test.php on line 67
call_user_func_array
期望将可调用对象作为第一个参数,而 $stmt->bind_param
是错误的格式。 [$stmt, 'bind_param']
将是正确的可调用对象
来源:https://www.php.net/manual/en/language.types.callable.php
A method of an instantiated object is passed as an array containing an object at index 0 and the method name at index 1. Accessing protected and private methods from within a class is allowed.
我想用call_user_func_array
这样绑定变量号参数(请阅读代码处的注释):
function dbQuery()
{
global $dbconnection;
if (func_num_args() < 1 || func_num_args() === 2) {
return error('خطای داخلی');
} else if (func_num_args() === 1) {
$stmt = $dbconnection->prepare(func_get_arg(0)); // Creating stmt
if (!$stmt) {
return error('خطای پایگاه داده');
}
if (!$stmt->execute()) {
return error('خطا در تعامل با پایگاه داده');
}
return $stmt;
} else {
$args = func_get_args();
$stmt = $dbconnection->prepare($args[0]); // args[0] is the query with question marks
if (!$stmt) {
return error('خطای پایگاه داده');
}
array_shift($args);
foreach ($args as $index => $arg) {
${'arg' . $index} = $dbconnection->real_escape_string($arg); // making args as variables because bind_params does not allow direct values
$args[$index] = ${'arg' . $index};
}
if (!call_user_func_array($stmt->bind_param,$args)) { // ERROR IS HERE LINE 67
return error('خطای امنیتی پایگاه داده');
}
if (!$stmt->execute()) {
return error('خطا در تعامل با پایگاه داده');
}
return $stmt;
}
}
$stmt = dbQuery('SELECT * FROM payments WHERE id=?','i',31);
$result = dbCheck($stmt);
var_dump($result->fetch_all());
错误是:
PHP Warning: Undefined property: mysqli_stmt::$bind_param in /home/mwxgaf/w/projects/foodorder/test.php on line 67
PHP Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($function) must be a valid callback, no array or string given in /home/mwxgaf/w/projects/foodorder/test.php:67
Stack trace:
#0 /home/mwxgaf/w/projects/foodorder/test.php(76): dbQuery()
#1 {main}
thrown in /home/mwxgaf/w/projects/foodorder/test.php on line 67
call_user_func_array
期望将可调用对象作为第一个参数,而 $stmt->bind_param
是错误的格式。 [$stmt, 'bind_param']
将是正确的可调用对象
来源:https://www.php.net/manual/en/language.types.callable.php
A method of an instantiated object is passed as an array containing an object at index 0 and the method name at index 1. Accessing protected and private methods from within a class is allowed.