inst-resources/postgresqlutil.php
author Dan
Tue, 08 Dec 2009 02:25:33 -0500
changeset 6 6016fd9e848f
parent 0 67e1cc6cd929
permissions -rw-r--r--
A couple minor fixes: more flexible version numbering; added a CreateDirectory before uninstaller generation (whoops)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     1
<?php
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     2
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     3
// PostgreSQL utility script.
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     4
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     5
if ( $argc < 2 )
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     6
  die("Usage: {$argv[0]} username password");
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     7
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     8
$user = addslashes($argv[1]);
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     9
$pass = addslashes($argv[2]);
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    10
$handle = pg_connect("host=localhost port=5432 user='$user' password='$pass'");
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    11
if ( !$handle )
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    12
{
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    13
  echo "PostgreSQL authentication failed.";
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    14
  exit(1);
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    15
}
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    16
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    17
if ( !empty($argv[3]) )
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    18
{
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    19
  $queries = explode(';', $argv[3]);
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    20
  foreach ( $queries as $query )
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    21
  {
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    22
    $query = trim($query);
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    23
    if ( empty($query) )
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    24
      continue;
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    25
    echo "$query;\n";
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    26
    if ( !pg_query("$query;") )
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    27
      exit(1);
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    28
  }
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    29
}
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    30
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    31
exit(0);