• PHP Video Tutorials

PHP - Function MySQLi Escape String



Syntax

mysqli_real_escape_string(connection,escapestring);

Definition and Usage

It function escapes special characters in a string for an SQL statement.

Return Values

It returns escaped string.

Parameters

Sr.No Parameters & Description
1

connection

It specifies about connection to use

2

escapestring

It specifies about the not escaped string

Example

Try out the following example

<?php
   $con = mysqli_connect("localhost","my_user","my_password","my_db");
   
   if (mysqli_connect_errno($con)){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   $myName = "Jr's";
   $myName = mysqli_real_escape_string($con,$myName);
   
   mysqli_query($con,"INSERT into emp (name) VALUES ('$myName')");
   mysqli_close($con);
?>
php_function_reference.htm
Advertisements