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

From: Date: Fri, 04 Sep 2015 21:04:10 +0000
Subject: svn: /phpdoc/en/trunk/reference/mysql/functions/ mysql-real-escape-string.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-13713@lists.php.net to get a copy of this message
philip Fri, 04 Sep 2015 21:04:10 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=337755 Log: Better late than never. Demonstrate that a connection is required, and what happens when one is not. Changed paths: U phpdoc/en/trunk/reference/mysql/functions/mysql-real-escape-string.xml Modified: phpdoc/en/trunk/reference/mysql/functions/mysql-real-escape-string.xml =================================================================== --- phpdoc/en/trunk/reference/mysql/functions/mysql-real-escape-string.xml 2015-09-04 20:56:08 UTC (rev 337754) +++ phpdoc/en/trunk/reference/mysql/functions/mysql-real-escape-string.xml 2015-09-04 21:04:10 UTC (rev 337755) @@ -77,6 +77,15 @@ </para> </refsect1> + <refsect1 role="errors"> + &reftitle.errors; + <para> + Executing this function without a MySQL connection present will + also emit <constant>E_WARNING</constant> level PHP errors. Only + execute this function with a valid MySQL connection present. + </para> + </refsect1> + <refsect1 role="examples"> &reftitle.examples; <para> @@ -100,6 +109,40 @@ </para> <para> <example> + <title><function>mysql_real_escape_string</function> requires a connection example</title> + <para> + This example demonstrates what happens if a MySQL connection is not + present when calling this function. + </para> + <programlisting role="php"> +<![CDATA[ +<?php +// We have not connected to MySQL + +$lastname = "O'Reilly"; +$_lastname = mysql_real_escape_string($lastname); + +$query = "SELECT * FROM actors WHERE last_name = '$_lastname'"; + +var_dump($_lastname); +var_dump($query); +?> +]]> + </programlisting> + &example.outputs.similar; + <screen> +<![CDATA[ +Warning: mysql_real_escape_string(): No such file or directory in /this/test/script.php on line 5 +Warning: mysql_real_escape_string(): A link to the server could not be established in /this/test/script.php on line 5 + +bool(false) +string(41) "SELECT * FROM actors WHERE last_name = ''" +]]> + </screen> + </example> + </para> + <para> + <example> <title>An example SQL Injection Attack</title> <programlisting role="php"> <![CDATA[

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