簡體   English   中英

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(或任何其他示例)中使用嗎?

最后我可以使用我的函數/類

$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方法,它將完美地綁定

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM