使用具有一个或没有值的准备语句

问题描述 投票:0回答:0

我一直在慢慢地将我所有的站点转换为我的 Ubuntu 开发系统上 mysql 中的准备好的语句,并且除了像这样的一些剩余问题之外,我正在掌握它。

这段代码是传入

$types
(即:“i”)和
$values
(即:“1”)的函数的一部分。有时 $values 在调用它的页面上被硬编码但如果只有一个或没有,它不会给出任何结果。

if (!empty($values)) :
    if (!is_array($values)) :
        $values = explode(',',$values);
    endif;
elseif (!empty($_POST)) :
    unset($_POST['Submit']);
    $values = $_POST;
endif;

if (!empty($types) && !empty($values)) :
    if ($stmt = $mysqli->prepare($Query)) :
        $stmt->bind_param($types, ...$values);
    endif;
endif;

我认为尝试从单个值或没有值但不确定创建数组时可能会遇到问题。有什么想法吗?

错误在这一行

$stmt->bind_param($types, ...$values);
为:

致命错误:未捕获的 ArgumentCountError:mysqli_stmt::bind_param() 不接受未知的命名参数 /var/www/html/common/mysql_functions.php:53 堆栈跟踪:#0 /var/www/html/common/mysql_functions.php(53): mysqli_stmt->bind_param() #1 /var/www/html/verifyyourvehicle.loc/internals/includes/header.php(15): 数据库连接()#2 /var/www/html/verifyyourvehicle.loc/internals/includes/pageheader.php(68): include('...') #3 /var/www/html/verifyyourvehicle.loc/index.php(3): include('...') #4 {main} 抛出 /var/www/html/common/mysql_functions.php 第 53 行

php mysql prepared-statement
© www.soinside.com 2019 - 2024. All rights reserved.