PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




mysql_escape_string() Function in PHP


Tutorials »Php »

Topic

What is mysql_escape_string() function in PHP?
How does mysql_escape_string() works?




Explanation

Mysql function mysql_escape_string() replaces characters such as %,_ and NULL that have a special meaning in MySQL with an escape sequence. The function is used to escape the individual values for a query, rather than an entire query string.

Syntax

string mysql_escape_string ( string unescaped_string)


This function is identical to mysql_real_escape_string() except that mysql_real_escape_string() takes a connection handler and escapes the string according to the current character set. mysql_escape_string() does not take a connection argument and does not respect the current charset setting. This function doesnot escape % and _.

Example:


<?php
$item = "Zak's Laptop";
$escaped_item = mysql_escape_string($item);
printf("Escaped string: %s\n", $escaped_item);
?>




In the above example string contain special characted single quotes, it is escaped by passing the string to mysql_escape_string() function. Here single quotes is espaced by adding a slash before characted to display the string as such.

RESULT:

Escaped string: Zak\'s Laptop

See also: mysql_real_escape_string()





Other Links

web hosting