PgBabylon is here!
October 7, 2015
No comments
Article
PgBabylon is a user-land extension to PHP PDO and PDOStatement native classes that helps to deal with PostgreSQL types like JSON, Arrays, etc.
It provides conversion between PHP types and PostgreSQL types and simplifies usage of SQL clauses like IN.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
// // Example: insert a PHP array in a PostgreSQL JSON field // use \PgBabylon\PDO; $arr = [ "name" => "Mark", "age" => 39, "address" => "White street, 23", "town" => "London" ]; $s = $pdo->prepare("INSERT INTO my_table(json) VALUES (:json) RETURNING json"); $s->execute([ ":json" => \PgBabylon\DataTypes\JSON($arr) ]); $s->setColumnType('json', PDO::PARAM_JSON); $r = $s->fetch(PDO::FETCH_MODE_ASSOC); print_r($r); // Output contains the JSON PostgreSQL column decoded as PHP Array: // // array( // "name" => "Mark" // "age" => 39, // "address" => "White street, 23" // "town" => "London" // ) // // |
Go and clone it on GitHub or install using composer
Categories: Planet Php, Planet PostgreSQL