PHP: pg_delete - Manual (original) (raw)
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_delete — Deletes records
Description
If flags is specified,pg_convert() is applied toconditions with the specified flags.
By default pg_delete() passes raw values. Values must be escaped or the [PGSQL_DML_ESCAPE](pgsql.constants.php#constant.pgsql-dml-escape) flag must be specified in flags.[PGSQL_DML_ESCAPE](pgsql.constants.php#constant.pgsql-dml-escape) quotes and escapes parameters/identifiers. Therefore, table/column names become case sensitive.
Note that neither escape nor prepared query can protect LIKE query, JSON, Array, Regex, etc. These parameters should be handled according to their contexts. i.e. Escape/validate values.
Changelog
| Version | Description |
|---|---|
| 8.1.0 | The connection parameter expects an PgSql\Connection instance now; previously, a resource was expected. |
Examples
Example #1 pg_delete() example
<?php $db = pg_connect('dbname=foo'); // This is safe somewhat, since all values are escaped. // However PostgreSQL supports JSON/Array. These are not // safe by neither escape nor prepared query. <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mi>e</mi><mi>s</mi><mo>=</mo><mi>p</mi><msub><mi>g</mi><mi>d</mi></msub><mi>e</mi><mi>l</mi><mi>e</mi><mi>t</mi><mi>e</mi><mo stretchy="false">(</mo></mrow><annotation encoding="application/x-tex">res = pg_delete(</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.4306em;"></span><span class="mord mathnormal">res</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">p</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3361em;"><span style="top:-2.55em;margin-left:-0.0359em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">d</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">e</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal">e</span><span class="mord mathnormal">t</span><span class="mord mathnormal">e</span><span class="mopen">(</span></span></span></span>db, 'post_log', $_POST, PG_DML_ESCAPE); if ($res) { echo "POST data is deleted: $res\n"; } else { echo "User must have sent wrong inputs\n"; } ?>
See Also
- pg_convert() - Convert associative array values into forms suitable for SQL statements
Found A Problem?
There are no user contributed notes for this page.