简体   繁体   English

PHP bind_param与数组

[英]PHP bind_param with arrays

Is it possible to use bind_param() with arrays? 是否可以将bind_param()与数组一起使用?

For example 例如

$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') ));

Is any of these examples possible in PHP (or any other examples)? 这些示例中的任何一个都可以在PHP(或任何其他示例)中使用吗?

Finally I can use my function/class 最后我可以使用我的函数/类

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

Function explination 功能探索

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)"
*/

My project will be out on GitHub really soon :) Thanks a lot! 我的项目很快就会出现在GitHub上:)非常感谢!

如果您的PHP没有过时(即=> 5.6),只需在第一个示例中添加三个点,

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM