有很多关于这个的问题在这里得到了回答,但我找不到我的问题。
使用存储为属性的 mysqli 的 DB 类。使用魔法调用方法触发准备、绑定和执行:
public static function __callStatic($name, $arg)
{
echo '<pre>';
var_dump($arg);
echo '</pre>';
if($name == 'Prepare'){
self::$Stmt = self::$mysqli->prepare(implode(', ', $arg));
$return = self::$Stmt;
}elseif($name == 'Bind')
$return = self::$Stmt->bind_param(implode(', ', $arg));
elseif($name == 'Execute')
$return = self::$Stmt->execute();
else
$return = self::$mysqli->$name(implode(', ', $arg));
if(!self::GetErr())
return $return;
}
我还有一个生成 SQL 语句的类。这是准备语句中使用的输出:
INSERT INTO account (UName, FName, LName, Email, Password, RecQuestion, RecAnswer, Admin) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
这是代码:
DB::Prepare(SQL::Table('account')->Insert([
'UName' => '?',
'FName' => '?',
'LName' => '?',
'Email' => '?',
'Password' => '?',
'RecQuestion' => '?',
'RecAnswer' => '?',
'Admin' => '?'
]));
DB::Bind('sssssssi', $userName, $fName, $lName, $email, $password, $recQ, $recA, $admin);
DB::Execute();
正如我所看到的,它有 8 种类型和 8 个值......
这里也是var_dump($arg)
当 DB::Bind 被调用时的输出
array(9) {
[0]=>
string(8) "sssssssi"
[1]=>
string(4) "user"
[2]=>
string(5) "first"
[3]=>
string(4) "last"
[4]=>
string(15) "email@email.com"
[5]=>
string(64) "$2a$10$Tw4eOkUYA6SX8WP8XJfKZeFfOM9htVRJyP0d1iYlka0jNCV/qPGzazakT"
[6]=>
string(7) "recover"
[7]=>
string(64) "$2a$10$LrfK2EdkRi6pPdx1tUtPWe8p24T8ISdQHYhW0N06RjbvCrU4Flqiie4jU"
[8]=>
int(1)
}