· 9 years ago · Oct 06, 2016, 08:01 PM
1<?php
2/**
3 * Created by IntelliJ IDEA.
4 * User: mpeveler
5 * Date: 10/6/16
6 * Time: 3:45 PM
7 */
8
9$pdo = new PDO('pgsql:dbname=postgres;host=localhost;port=15432', 'hsdbu', 'hsdbu');
10$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
11$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
12
13$query = $pdo->prepare("
14CREATE TABLE IF NOT EXISTS test (
15 test_column TEXT[]
16)
17");
18$query->execute();
19
20// this'll work
21$a = array('a', 'b', 'c');
22
23// this'll throw a PDO exception
24$a = array('a"', 'b', 'c');
25
26// this'll insert {"a, b", c}
27$a = array('a\\', 'b', 'c');
28
29
30$query = $pdo->prepare("INSERT INTO test (test_column) VALUES (?)");
31$query->execute(array("{".implode(",", $a)."}"));
32
33$pdo = null;