inst-resources/mysqlutil.php
author Dan
Sat, 11 Jul 2009 10:07:32 -0400
changeset 3 0cce88c7cf7c
parent 0 67e1cc6cd929
permissions -rw-r--r--
Added Makefile
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
// MySQL 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]} port 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 = $argv[2];
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
     9
$pass = $argv[3];
67e1cc6cd929 First commit. It's working!
Dan
parents:
diff changeset
    10
$handle = mysql_connect("localhost:{$argv[1]}", $user, $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 "MySQL 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[4]) )
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[4]);
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 ( !mysql_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);