adding escaping example

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@280938 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Damien Seguy 2009-05-22 10:24:08 +00:00
parent 417e015ab2
commit 2227cbe69a

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 1.1 $ -->
<!-- $Revision: 1.2 $ -->
<refentry xml:id="pdo-4d.examples" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
@ -194,6 +194,64 @@ $db = null;
</example>
</para>
</refsect1>
<refsect1 role="description">
<para>
<example>
<title>Escaping 4D table names</title>
<para>
This examples illustrates how to escape characters in a
4D SQL query.
</para>
<programlisting role="php">
<![CDATA[
<?php
$dsn = '4D:host=localhost;charset=UTF-8';
$user = 'test';
$pass = 'test';
 
// Connection to 4D server 4D
$db = new PDO_4D($dsn, $user, $pass);
$objects = array('[',']','[]','][','[[',']]','[[[',']]]','TBL ]]32[23');
foreach($objects as $id => $object) {
$object = str_replace(']',']]', $object);
print "$object\n";
$db->exec('CREATE TABLE IF NOT EXISTS ['.$object.'](['.$object.'] FLOAT)');
$req = "INSERT INTO [$object] ([$object]) VALUES ($id);";
$db->query($req);
$q = $db->prepare("SELECT [$object] FROM [$object]");
$q->execute();
$x[] = $q->fetch(PDO::FETCH_NUM);
$db->exec('DROP TABLE ['.$object.'];');
}
?>
]]>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
[
]]
[]]
]][
[[
]]]]
[[[
]]]]]]
TBL ]]]]32[23
]]>
</screen>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file