在php手册http://php.net/manual/en/mysqli-stmt.bind-param.php
中我看到这样的代码:
$stmt->bind_param('sssd', $code, $language, $official, $percent);
$code = 'DEU';
$language = 'Bavarian';
$official = "F";
$percent = 11.2;
/* execute prepared statement */
$stmt->execute();
答案 0 :(得分:1)
bind_param()
方法存储对$code
,$language
,$official
和$percent
变量的值的引用。引用存储在$stmt
对象中。
当您提供变量值时,$stmt
对象已知道在哪里查找值。
我们可以自己创建一个类:
class Play {
protected $reference;
public function bind( & $variable) {
$this->reference = &$variable;
}
public function show() {
echo "{$this->reference}<br>\n";
}
}
&
字符是引用运算符。当您使用它时,您将获得对另一个变量的值的引用。
通过这个课程,我们可以创建一个对象,并获得一些乐趣:
$play = new Play;
$play->bind($string);
$string = 'Hello!';
$play->show();
$string = 'World!';
$play->show();
答案 1 :(得分:-1)
在编写声明之前,没有php不能使用变量!
在语句存在之前,任何语言显然都无法输出。