PHP Mysql to Mysqli mistakes >> mysqli_real_escape_string expects exactly 2 parameters
Rishi Kashyap
8.72 K
X

mysqli_real_escape_string expects exactly 2 parameters


0

mysqli_real_escape_string expects exactly 2 parameters
When migrating from mysql to mysqli, if you were using mysql_real_escape_string for escaping the data then you need to add an additional parameter, the link identifier(connection) to mysqli_real_escape_string else Error "mysqli_real_escape_string expects exactly 2 parameters 1 given" will result. so simple PHP Mysql Code<?php
$link = mysql_connect('localhost','user','password') or die(mysql_error());
$string="string to escape";
$escaped_string=mysql_real_escape_string($string) or die(mysql_error());
echo $escaped_string;
?>
But when using mysqli_real_escape_string(), the link comes first followed by the string to escape. Simple PHP Mysqli code in procedural style<?php
$link = mysqli_connect('localhost','user','password') or die(mysqli_error($link));
$string="string to escape";
$escaped_string=mysqli_real_escape_string($link,$string) or die(mysqli_error($link));
echo $escaped_string;
?>

Rishi Kashyap | | EDIT

SHARE Whatsapp Facebook Twitter To TOP