cvs: phpdoc /en/reference/mysql/functions mysql-real-escape-string.xml

From: Date: Sat, 16 May 2009 13:43:53 +0000
Subject: cvs: phpdoc /en/reference/mysql/functions mysql-real-escape-string.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-4021@lists.php.net to get a copy of this message
aidan Sat May 16 13:43:53 2009 UTC Modified files: /phpdoc/en/reference/mysql/functions mysql-real-escape-string.xml Log: Remove terrible "best practice" example http://cvs.php.net/viewvc.cgi/phpdoc/en/reference/mysql/functions/mysql-real-escape-string.xml?r1=1.30&r2=1.31&diff_format=u Index: phpdoc/en/reference/mysql/functions/mysql-real-escape-string.xml diff -u phpdoc/en/reference/mysql/functions/mysql-real-escape-string.xml:1.30 phpdoc/en/reference/mysql/functions/mysql-real-escape-string.xml:1.31 --- phpdoc/en/reference/mysql/functions/mysql-real-escape-string.xml:1.30 Fri Jun 29 11:42:12 2007 +++ phpdoc/en/reference/mysql/functions/mysql-real-escape-string.xml Sat May 16 13:43:53 2009 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.30 $ --> +<!-- $Revision: 1.31 $ --> <refentry xml:id="function.mysql-real-escape-string" xmlns="http://docbook.org/ns/docbook"> <refnamediv> <refname>mysql_real_escape_string</refname> @@ -109,64 +109,6 @@ </para> </example> </para> - <para> - <example> - <title>A "Best Practice" query</title> - <para> - Using <function>mysql_real_escape_string</function> around each variable - prevents SQL Injection. This example demonstrates the "best practice" - method for querying a database, independent of the - <link linkend="security.magicquotes">Magic Quotes</link> setting. - </para> - <programlisting role="php"> -<![CDATA[ -<?php - -if (isset($_POST['product_name']) && isset($_POST['product_description']) && isset($_POST['user_id'])) { - // Connect - - $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password'); - - if(!is_resource($link)) { - - echo "Failed to connect to the server\n"; - // ... log the error properly - - } else { - - // Reverse magic_quotes_gpc/magic_quotes_sybase effects on those vars if ON. - - if(get_magic_quotes_gpc()) { - $product_name = stripslashes($_POST['product_name']); - $product_description = stripslashes($_POST['product_description']); - } else { - $product_name = $_POST['product_name']; - $product_description = $_POST['product_description']; - } - - // Make a safe query - $query = sprintf("INSERT INTO products (name, description, user_id) VALUES ('%s', '%s', %d)", - mysql_real_escape_string($product_name, $link), - mysql_real_escape_string($product_description, $link), - $_POST['user_id']); - - mysql_query($query, $link); - - if (mysql_affected_rows($link) > 0) { - echo "Product inserted\n"; - } - } -} else { - echo "Fill the form properly\n"; -} -?> -]]> - </programlisting> - <para> - The query will now execute correctly, and SQL Injection attacks will not work. - </para> - </example> - </para> </refsect1> <refsect1 role="notes">

« previous php.doc.cvs (#4021) next »