-1

I update php 5 to php 7 quite recently.so that when i run the project it gives following error.

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\Project\Duplicate - Copy (2)\general.php on line 5

Here is the Code.

<?php
function sanitize($data){   
    return mysqli_real_escape_string($data);
}
?>

then i recoded connection like this.

$db = new PDO('mysql:host=localhost;dbname=test;charset=utf8mb4', 'root', "");

can anyone help me please!

Dasun
  • 602
  • 1
  • 11
  • 34
  • 4
    Umm.. _expects exactly 2 parameters, 1 given_ what does that tell you? Did you look at the manual??? – AbraCadaver Mar 01 '17 at 16:45
  • When i use php 5 version .code works fine,but now it says like that – Dasun Mar 01 '17 at 16:46
  • 1
    You mean you had warnings turned off in php 5? – jeroen Mar 01 '17 at 16:48
  • 1
    @Dasun You're not using PHP5 and `mysql_*` anymore so read the documentation for PHP7's `mysqli_*` because it is different. Old `string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier = NULL ] )` vs new `string mysqli_real_escape_string ( mysqli $link , string $escapestr )` is different for a reason. – MonkeyZeus Mar 01 '17 at 16:49
  • @jeroen This is likely a migration effort from `mysql_*` to `mysqli_*` – MonkeyZeus Mar 01 '17 at 16:50
  • @MonkeyZeus That's possible, but with 1 line of PDO and 1 line of mysqli it could be anything... – jeroen Mar 01 '17 at 16:53
  • i change code like this `function sanitize($db, $data){ return mysql_real_escape_string($data); } ?>` So error was gone – Dasun Mar 01 '17 at 17:02
  • But Now problem is here ** Uncaught Error: Call to undefined function mysql_real_escape_string() ** what is that? – Dasun Mar 01 '17 at 17:05

1 Answers1

2

Did you read the documentation?

The first parameter needs to be your connection object.

You also however you appear to be mixing and matching PDO and mysqli functions.

Pick one or the other.

Matt Clark
  • 27,671
  • 19
  • 68
  • 123