带数组的PHP绑定参数
可以与阵列一起使用吗 比如说带数组的PHP绑定参数,php,mysqli,prepared-statement,bindparam,Php,Mysqli,Prepared Statement,Bindparam,可以与阵列一起使用吗 比如说 $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',
$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(或任何其他示例)中是否可以使用这些示例
最后,我可以使用我的函数/类
$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方法中,它会完美地绑定我不相信这些都是可能的。但这可能是错误的。试试看?谢谢@YourCommonSense的帮助,现在已经做了一个编辑来解释为什么我需要这个来处理阵列。我将有一个tryCan i do
$stmt->bind_param($identifiers,$array)你刚才说你要试试。是吗?还没有,我试试看now@ringø难怪这种语法与bind_param无关,因为它是一种全语言特性,参数解包operator@RichardOlsenSandberg为什么你认为它对PDO不起作用?因为{
和}
不是数组,最有可能是对象,但也从来没有让它们作为对象工作过