|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<refentry xml:id="pdo-pgsql.escapeidentifier" xmlns="http://docbook.org/ns/docbook"> |
| 3 | + <refnamediv> |
| 4 | + <refname>Pdo\Pgsql::escapeIdentifier</refname> |
| 5 | + <refpurpose>Escapes a string for use as an SQL identifier</refpurpose> |
| 6 | + </refnamediv> |
| 7 | + |
| 8 | + <refsect1 role="description"> |
| 9 | + &reftitle.description; |
| 10 | + <methodsynopsis role="Pdo\\Pgsql"> |
| 11 | + <modifier>public</modifier> <type>string</type><methodname>Pdo\Pgsql::escapeIdentifier</methodname> |
| 12 | + <methodparam><type>string</type><parameter>input</parameter></methodparam> |
| 13 | + </methodsynopsis> |
| 14 | + <simpara> |
| 15 | + Escapes a string for use as an SQL identifier, such as a table, column, or function name. |
| 16 | + This is useful when a user-supplied identifier might contain special characters |
| 17 | + that would otherwise not be interpreted as part of the identifier by the SQL parser, |
| 18 | + or when the identifier might contain upper case characters whose case should be preserved. |
| 19 | + </simpara> |
| 20 | + </refsect1> |
| 21 | + |
| 22 | + <refsect1 role="parameters"> |
| 23 | + &reftitle.parameters; |
| 24 | + <variablelist> |
| 25 | + <varlistentry> |
| 26 | + <term><parameter>input</parameter></term> |
| 27 | + <listitem> |
| 28 | + <simpara> |
| 29 | + A <type>string</type> containing text to be escaped. |
| 30 | + </simpara> |
| 31 | + </listitem> |
| 32 | + </varlistentry> |
| 33 | + </variablelist> |
| 34 | + </refsect1> |
| 35 | + |
| 36 | + <refsect1 role="returnvalues"> |
| 37 | + &reftitle.returnvalues; |
| 38 | + <simpara> |
| 39 | + A <type>string</type> containing the escaped data. |
| 40 | + </simpara> |
| 41 | + </refsect1> |
| 42 | + |
| 43 | + <refsect1 role="examples"> |
| 44 | + &reftitle.examples; |
| 45 | + <example xml:id="pdo-pgsql.escapeidentifier.example.basic"> |
| 46 | + <title><methodname>Pdo\Pgsql::escapeIdentifier</methodname> example</title> |
| 47 | + <programlisting role="php"> |
| 48 | +<![CDATA[ |
| 49 | +<?php |
| 50 | +$pdo = new Pdo\Pgsql('pgsql:dbname=test host=localhost', $user, $pass); |
| 51 | +
|
| 52 | +$unescapedTableName = 'UnescapedTableName'; |
| 53 | +$pdo->exec("CREATE TABLE $unescapedTableName ()"); |
| 54 | +
|
| 55 | +$escapedTableName = $pdo->escapeIdentifier('EscapedTableName'); |
| 56 | +$pdo->exec("CREATE TABLE $escapedTableName ()"); |
| 57 | +
|
| 58 | +$statement = $pdo->query( |
| 59 | + "SELECT relname FROM pg_stat_user_tables WHERE relname ilike '%tablename'" |
| 60 | +); |
| 61 | +
|
| 62 | +var_export($statement->fetchAll(PDO::FETCH_COLUMN, 0)); |
| 63 | +
|
| 64 | +$tableNameWithSymbols = 'Table-Name-With-Symbols'; |
| 65 | +$pdo->exec("CREATE TABLE $tableNameWithSymbols ()"); |
| 66 | +?> |
| 67 | +]]> |
| 68 | + </programlisting> |
| 69 | + &example.outputs.similar; |
| 70 | + <screen> |
| 71 | +<![CDATA[ |
| 72 | +array ( |
| 73 | + 0 => 'unescapedtablename', |
| 74 | + 1 => 'EscapedTableName', |
| 75 | +) |
| 76 | +Fatal error: Uncaught PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "Table" |
| 77 | +LINE 1: CREATE TABLE Table-Name-With-Symbols () |
| 78 | +]]> |
| 79 | + </screen> |
| 80 | + </example> |
| 81 | + </refsect1> |
| 82 | + |
| 83 | + <refsect1 role="seealso"> |
| 84 | + &reftitle.seealso; |
| 85 | + <simplelist> |
| 86 | + <member><methodname>PDO::quote</methodname></member> |
| 87 | + </simplelist> |
| 88 | + </refsect1> |
| 89 | + |
| 90 | +</refentry> |
| 91 | +<!-- Keep this comment at the end of the file |
| 92 | +Local variables: |
| 93 | +mode: sgml |
| 94 | +sgml-omittag:t |
| 95 | +sgml-shorttag:t |
| 96 | +sgml-minimize-attributes:nil |
| 97 | +sgml-always-quote-attributes:t |
| 98 | +sgml-indent-step:1 |
| 99 | +sgml-indent-data:t |
| 100 | +indent-tabs-mode:nil |
| 101 | +sgml-parent-document:nil |
| 102 | +sgml-default-dtd-file:"~/.phpdoc/manual.ced" |
| 103 | +sgml-exposed-tags:nil |
| 104 | +sgml-local-catalogs:nil |
| 105 | +sgml-local-ecat-files:nil |
| 106 | +End: |
| 107 | +vim600: syn=xml fen fdm=syntax fdl=2 si |
| 108 | +vim: et tw=78 syn=sgml |
| 109 | +vi: ts=1 sw=1 |
| 110 | +--> |
0 commit comments