diff options
author | Liam McLoughlin <hexxeh@hexxeh.net> | 2011-07-27 20:29:49 +0100 |
---|---|---|
committer | Liam McLoughlin <hexxeh@hexxeh.net> | 2011-07-27 20:29:49 +0100 |
commit | 5099c71493abe193f23b7f0a7381e539bc67bb33 (patch) | |
tree | 7628542c989bace2895427d34959b5f3fcbd2150 /status.php | |
parent | Added disk size cap (diff) | |
download | gentoaster-5099c71493abe193f23b7f0a7381e539bc67bb33.tar.gz gentoaster-5099c71493abe193f23b7f0a7381e539bc67bb33.tar.bz2 gentoaster-5099c71493abe193f23b7f0a7381e539bc67bb33.zip |
Moved to using mysqli and prepared statements
Diffstat (limited to 'status.php')
-rw-r--r-- | status.php | 40 |
1 files changed, 24 insertions, 16 deletions
@@ -8,17 +8,21 @@ if (!isset($argv[1])) { die("No handle hash given\n"); } - $db = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD); - if (!$db) { - die("Could not connect to database ".mysql_error()."\n"); + + $db = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME, + MYSQL_PASSWORD, MYSQL_DATABASE); + if (mysqli_connect_errno()) { + die("Could not connect to database ".mysqli_connect_error()); } - mysql_select_db(MYSQL_DATABASE); - $query = "SELECT handle FROM builds ". - "WHERE id = '".mysql_real_escape_string($argv[1])."'"; - $result = mysql_query($query); - if (mysql_num_rows($result) == 1) { - $handles = mysql_fetch_array($result); - $handle = $handles[0]; + + $query = "SELECT handle FROM builds WHERE id = ?"; + $stmt = $db->prepare($query); + $stmt->bind_param("s", $argv[1]); + $stmt->execute(); + $stmt->store_result(); + if ($stmt->num_rows == 1) { + $stmt->bind_result($handle); + $stmt->close(); $client = new GearmanClient(); $client->addServer(); @@ -33,11 +37,14 @@ } } else { $query = "SELECT returncode, result FROM builds ". - "WHERE id = '".mysql_real_escape_string($argv[1])."'"; - $result = mysql_query($query); - $jobres = mysql_fetch_array($result); - if ($jobres[0] !== null) { - echo "Job returned with code ".$jobres[0].": ".$jobres[1]."\n"; + "WHERE id = ?"; + $stmt = $db->prepare($query); + $stmt->bind_param("s", $argv[1]); + $stmt->execute(); + $stmt->bind_result($returncode, $result); + $stmt->fetch(); + if ($returncode !== null) { + echo "Job returned with code ".$returncode.": ".$result."\n"; } else { echo "Job failed\n"; } @@ -45,4 +52,5 @@ } else { echo "Invalid handle hash\n"; } - + + $db->close();
\ No newline at end of file |