0
|
1 |
<?php
|
|
2 |
|
|
3 |
// PostgreSQL utility script.
|
|
4 |
|
|
5 |
if ( $argc < 2 )
|
|
6 |
die("Usage: {$argv[0]} username password");
|
|
7 |
|
|
8 |
$user = addslashes($argv[1]);
|
|
9 |
$pass = addslashes($argv[2]);
|
|
10 |
$handle = pg_connect("host=localhost port=5432 user='$user' password='$pass'");
|
|
11 |
if ( !$handle )
|
|
12 |
{
|
|
13 |
echo "PostgreSQL authentication failed.";
|
|
14 |
exit(1);
|
|
15 |
}
|
|
16 |
|
|
17 |
if ( !empty($argv[3]) )
|
|
18 |
{
|
|
19 |
$queries = explode(';', $argv[3]);
|
|
20 |
foreach ( $queries as $query )
|
|
21 |
{
|
|
22 |
$query = trim($query);
|
|
23 |
if ( empty($query) )
|
|
24 |
continue;
|
|
25 |
echo "$query;\n";
|
|
26 |
if ( !pg_query("$query;") )
|
|
27 |
exit(1);
|
|
28 |
}
|
|
29 |
}
|
|
30 |
|
|
31 |
exit(0);
|