This question already has an answer here:
Following is the code:
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)."'";
}
}
I am getting the following error in the quote function: Parse error: syntax error, unexpected '$value' (T_VARIABLE) in D:\xampp\htdocs\fizzy\submit.php on line 48
</div>
Might be there is no value in $value. So you can do like this:
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;
}
}
Change string $value
to (string) $value
remove string
public function quote($value){
$connection = $this -> connect();
return "'".$connection -> real_escape_string($value)."'";
^
}
Take a look at last code line
return "'".$connection -> real_escape_string(string $value)."'";
Here parameter passed to function is (string $value)
.As you are type casting $value
,it should be ((string)$value)
.