forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01createdb.phpt
52 lines (45 loc) · 1.21 KB
/
01createdb.phpt
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--TEST--
PostgreSQL create db
--EXTENSIONS--
pgsql
--SKIPIF--
<?php include("inc/skipif.inc"); ?>
--FILE--
<?php
// create test table
include('inc/config.inc');
$table_name = 'table_01createdb';
$table_name_92 = 'table_01createdb_92';
$view_name = "view_01createdb";
$db = pg_connect($conn_str);
if (!($q = @pg_query($db, "SELECT * FROM ".$table_name)) || !@pg_num_rows($q))
{
pg_query($db, "CREATE TABLE {$table_name} (num int, str text, bin bytea)"); // Create table here
}
else {
echo pg_last_error()."\n";
}
$v = pg_version($db);
if (version_compare($v['server'], '9.2', '>=') && (!($q = @pg_query($db, "SELECT * FROM ".$table_name_92)) || !@pg_num_rows($q)))
{
pg_query($db, "CREATE TABLE {$table_name_92} (textary text[], jsn json)"); // Create table here
}
else {
echo pg_last_error()."\n";
}
// Create view here
pg_query($db, "CREATE VIEW {$view_name} AS SELECT * FROM {$table_name}");
pg_close($db);
echo "OK";
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = 'table_01createdb';
$table_name_92 = 'table_01createdb_92';
$db = pg_connect($conn_str);
pg_query($db, "DROP TABLE IF EXISTS {$table_name} cascade");
pg_query($db, "DROP TABLE IF EXISTS {$table_name_92} cascade");
?>
--EXPECT--
OK