PHP mysqli_real_escape_string() Function

Definition

The mysqli_real_escape_string() function escapes special characters in a string for an SQL statement.

Syntax

PHP mysqli_real_escape_string() Function has the following syntax.

mysqli_real_escape_string(connection,escapestring);

Parameter

ParameterIs RequiredDescription
connectionRequired.MySQL connection
escapestringRequired.The not escaped string.

Return

It returns the escaped string.

Example

Escape special characters in a string for an SQL statement


<?php// w ww .  j a v a 2s .  c om
$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);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions