以下是代码:
class Db{
protected static $connection;
public function connect(){
if (!isset(self::$connection)) {
$config = parse_ini_file('../config.ini');
self::$connection = new mysqli('localhost',$config['username'],$config['password'],$config['dbname']);
}
if (self::$connection === false) {
die("Error in database connection. Please contact network administrator.");
return false;
}
return self::$connection;
}
public function quote($value){
$connection = $this -> connect();
return "'".$connection -> real_escape_string(string $value)."'";
}
}
我在引用函数中收到以下错误: 解析错误:语法错误,意外' $ value'第48行的D:\ xampp \ htdocs \ fizzy \ submit.php中的(T_VARIABLE)
答案 0 :(得分:0)
可能没有$ value的价值。所以你可以这样做:
public function quote($value = ""){
OR
public function quote($value){
if(isset($value) && $value != "") {
$connection = $this -> connect();
return "'".$connection -> real_escape_string(string ($value))."'";
} else {
return false;
}
}
答案 1 :(得分:0)
将string $value
更改为(string) $value
答案 2 :(得分:0)
删除string
public function quote($value){
$connection = $this -> connect();
return "'".$connection -> real_escape_string($value)."'";
^
}
答案 3 :(得分:0)
查看最后一行代码
return "'".$connection -> real_escape_string(string $value)."'";
此处传递给函数的参数为(string $value)
。当您输入$value
时,它应为((string)$value)
。