2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2004-07-21 04:27:29 +00:00
|
|
|
<!-- $Revision: 1.9 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.100 -->
|
|
|
|
<refentry id="function.mysql-real-escape-string">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>mysql_real_escape_string</refname>
|
|
|
|
<refpurpose>
|
|
|
|
Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection.
|
|
|
|
</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>string</type><methodname>mysql_real_escape_string</methodname>
|
|
|
|
<methodparam><type>string</type><parameter>unescaped_string</parameter></methodparam>
|
|
|
|
<methodparam choice="opt"><type>resource</type><parameter>link_identifier</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
|
|
|
This function will escape special characters in the
|
|
|
|
<parameter>unescaped_string</parameter>, taking into account the current
|
|
|
|
charset of the connection so that it is safe to place it in a
|
|
|
|
<function>mysql_query</function>.
|
|
|
|
</para>
|
|
|
|
<note>
|
|
|
|
<simpara>
|
|
|
|
<function>mysql_real_escape_string</function> does not escape
|
|
|
|
<literal>%</literal> and <literal>_</literal>.
|
|
|
|
</simpara>
|
|
|
|
</note>
|
2003-07-09 15:07:29 +00:00
|
|
|
<para>
|
2002-04-15 00:12:54 +00:00
|
|
|
<example>
|
|
|
|
<title><function>mysql_real_escape_string</function> example</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2004-02-20 17:36:42 +00:00
|
|
|
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
|
|
|
if (!$link) {
|
|
|
|
die('Could not connect: ' . mysql_error());
|
|
|
|
}
|
2002-04-15 00:12:54 +00:00
|
|
|
$item = "Zak's and Derick's Laptop";
|
2004-01-12 20:39:39 +00:00
|
|
|
$escaped_item = mysql_real_escape_string($item, $link);
|
2003-12-15 16:55:22 +00:00
|
|
|
printf("Escaped string: %s\n", $escaped_item);
|
2002-04-15 00:12:54 +00:00
|
|
|
?>
|
|
|
|
]]>
|
|
|
|
</programlisting>
|
|
|
|
<para>
|
|
|
|
The above example would produce the following output:
|
2003-07-09 15:07:29 +00:00
|
|
|
</para>
|
|
|
|
<screen>
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
|
|
|
Escaped string: Zak\'s and Derick\'s Laptop
|
|
|
|
]]>
|
2003-07-09 15:07:29 +00:00
|
|
|
</screen>
|
2002-04-15 00:12:54 +00:00
|
|
|
</example>
|
2003-07-09 15:07:29 +00:00
|
|
|
</para>
|
2002-04-15 00:12:54 +00:00
|
|
|
<para>
|
2003-07-09 15:07:29 +00:00
|
|
|
See also
|
2004-07-21 04:27:29 +00:00
|
|
|
<function>mysql_escape_string</function>,
|
|
|
|
<function>mysql_client_encoding</function>,
|
|
|
|
<function>addslashes</function>, and the
|
|
|
|
<link linkend="ini.magic-quotes-gpc">magic_quotes_gpc</link>
|
|
|
|
directive.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|