PHP bind_param 与数组

PHP bind_param with arrays

是否可以将 bind_param() 与数组一起使用?

例如

$stmt->bind_param('iss', Array(101, 'SomeString 1', 'Some string 2'));
// OR
$stmt->bind_param(Array('iss'), Array(101, 'String1', 'String2'));
// OR
$stmt->bind_param(Array( Array('i', 101), Array('s', 'String1'), Array('s', 'String2') ));

在PHP(或任何其他示例)中这些示例中的任何一个都可能吗?

我终于可以使用我的 function/class

$sql->upload( $table, Array('n;id', 's;username=' . $username, 's;password=' . $password) );

函数说明

public function upload( String $table , Array $values )

// Where example array could be Array('s;column=someString', 'i;SomeIntegerColumn=10', 'n;SomeID')
/*
    identifier;column=value
    Basically where identifier can be "n", "d", "i" or "s"
    column is the name of the sql column to inset the value to
    value is the string/integer/double to instert in the the column

    Example query with the array mentioned above would be
    "INSERT INTO $table(column, SomeIntegerColumn, SomeID) VALUES(?, ?, NULL)"
*/

我的项目很快就会在 GitHub 上发布 :) 非常感谢!

如果你的PHP没有过时(即>=5.6),只需在第一个例子上加三个点,

$stmt->bind_param('iss', ...array(101, 'SomeString 1', 'Some string 2'));

实际上你可以做得更好,如果你有一个数组,{'user' => 'John', 'age' => '20'},并且在你的声明中你把具有相同名称的参数,:name, :age,你可以将这个数组作为参数传递到 execute 方法中,它将完美绑定