PHP mysqli_real_escape_string() Function
In this chapter you will learn:
- Definition for PHP mysqli_real_escape_string() Function
- Syntax for PHP mysqli_real_escape_string() Function
- Parameter for PHP mysqli_real_escape_string() Function
- Return for PHP mysqli_real_escape_string() Function
- Example - escapes special characters in a string for an SQL statement
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
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
escapestring | Required. | The not escaped string. |
Return
It returns the escaped string.
Example
Escape special characters in a string for an SQL statement
<?php//from j a va2 s . c o m
$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);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_refresh() Function
- Syntax for PHP mysqli_refresh() Function
- Parameter for PHP mysqli_refresh() Function
- Return for PHP mysqli_refresh() Function
- Example - refreshes tables or caches, or resets the replication server information
Home » PHP Tutorial » PHP MySQLi Functions