Skip to content

Commit

Permalink
convert web app to use PDO to be able to use both mysql and postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
robkooper committed Jan 26, 2014
1 parent accc3db commit 8c4346d
Show file tree
Hide file tree
Showing 22 changed files with 224 additions and 271 deletions.
15 changes: 7 additions & 8 deletions web/advanced_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
}
$workflowid=$_REQUEST['workflowid'];

// database parameters
// database parameters
require("dbinfo.php");
$connection=open_database();
// connect to database
require("system.php");
$pdo = new PDO("${db_type}:host=${db_hostname};dbname=${db_database}", ${db_username}, ${db_password});

// get run information
$query = "SELECT site_id, model_id, model_type, hostname, folder, advanced_edit FROM workflows, models WHERE workflows.id=$workflowid and model_id=models.id";
$result = mysql_query($query);
$result = $pdo->query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
die('Invalid query: ' . $pdo->errorInfo());
}
$workflow = mysql_fetch_assoc($result);
$workflow = $result->fetch(PDO::FETCH_ASSOC);
$folder = $workflow['folder'];

// get information about all runs
Expand Down Expand Up @@ -169,5 +168,5 @@ function endsWith(haystack, needle) {
</html>

<?php
close_database($connection);
$pdo = null;
?>
9 changes: 4 additions & 5 deletions web/dataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@

// database parameters
require("system.php");
require("dbinfo.php");
$connection=open_database();
$pdo = new PDO("${db_type}:host=${db_hostname};dbname=${db_database}", ${db_username}, ${db_password});

// get run information
$query = "SELECT folder FROM workflows WHERE workflows.id=${workflowid}";
$result = mysql_query($query);
$result = $pdo->query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
die('Invalid query: ' . $pdo->errorInfo());
}
$run = mysql_fetch_assoc($result);
$run = $result->fetch(PDO::FETCH_ASSOC);
$folder = str_replace("//", "/", $run['folder']);

// return dataset
Expand Down
28 changes: 14 additions & 14 deletions web/db/BETY/inputs_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

if ($_REQUEST['action'] == "add") {
$query = "UPDATE dbfiles, inputs SET dbfiles.container_id=inputs.id, container_type='Input' WHERE dbfiles.id={$_REQUEST['dbid']} AND inputs.id=${id};";
if (!mysql_query($query, $db_connection)) {
$msg = "Error updating database : [" . mysql_errno($db_connection) . "] " . mysql_error($db_connection) . "<br>";
if (!$pdo->query($query, $db_connection)) {
$msg = "Error updating database : [" . $db_connection->errorInfo() . "] " . $pdo->errorInfo($db_connection) . "<br>";
editor_log("FAIL", $query);
} else {
$msg .= "Added dbfiles={$_REQUEST['dbid']} to inputs={$_REQUEST['id']}<br/>\n";
Expand All @@ -38,8 +38,8 @@

if ($_REQUEST['action'] == "del") {
$query = "UPDATE dbfiles SET container_id=NULL WHERE id={$_REQUEST['dbid']};";
if (!mysql_query($query, $db_connection)) {
$msg = "Error updating database : [" . mysql_errno($db_connection) . "] " . mysql_error($db_connection) . "<br>";
if (!$pdo->query($query, $db_connection)) {
$msg = "Error updating database : [" . $db_connection->errorInfo() . "] " . $pdo->errorInfo($db_connection) . "<br>";
editor_log("FAIL", $query);
} else {
$msg .= "Removed dbfiles={$_REQUEST['dbid']} from inputs={$_REQUEST['id']}<br/>\n";
Expand Down Expand Up @@ -83,11 +83,11 @@ function edit_input(id) {
$query="SELECT dbfiles.id, concat(machines.hostname, ':', dbfiles.file_path, '/', dbfiles.file_name) as filename" .
" FROM dbfiles, machines, inputs" .
" WHERE inputs.id=$id AND dbfiles.container_id=inputs.id AND dbfiles.container_type='Input' AND machines.id=dbfiles.machine_id;";
$result = mysql_query($query, $db_connection);
$result = $pdo->query($query, $db_connection);
if (!$result) {
die("Invalid query [$query] " . mysql_error($db_connection));
die("Invalid query [$query] " . $pdo->errorInfo($db_connection));
}
if (mysql_num_rows($result) > 0) {
if ($result->fetchColumn() > 0) {
?>
<div class="tbl" id="editor">
<div class="row">
Expand All @@ -99,14 +99,14 @@ function edit_input(id) {
<div class="val">
<select id="delfile">
<?php
while($dbfilerow = @mysql_fetch_assoc($result)) {
while($dbfilerow = @$result->fetch(PDO::FETCH_ASSOC)) {
if (isset($_REQUEST['dbid']) && ($_REQUEST['dbid'] == $dbfilerow['id'])) {
print "<option value=\"{$dbfilerow['id']}\" selected>{$dbfilerow['filename']}</option>\n";
} else {
print "<option value=\"{$dbfilerow['id']}\">{$dbfilerow['filename']}</option>\n";
}
}
mysql_free_result($result);
$result->closeCursor();
?>
</select>
</div>
Expand All @@ -122,11 +122,11 @@ function edit_input(id) {
" FROM dbfiles, machines" .
" WHERE machines.id = dbfiles.machine_id AND NOT EXISTS ( SELECT 1 FROM inputs WHERE dbfiles.container_id=inputs.id AND dbfiles.container_type='Input' ) " .
" ORDER BY filename;";
$result = mysql_query($query, $db_connection);
$result = $pdo->query($query, $db_connection);
if (!$result) {
die("Invalid query [$query] " . mysql_error());
die("Invalid query [$query] " . $pdo->errorInfo());
}
if (mysql_num_rows($result) > 0) {
if ($result->fetchColumn() > 0) {
?>
<div class="tbl" id="editor">
<div class="row">
Expand All @@ -138,7 +138,7 @@ function edit_input(id) {
<div class="val">
<select id="addfile">
<?php
while($dbfilerow = @mysql_fetch_assoc($result)) {
while($dbfilerow = @$result->fetch(PDO::FETCH_ASSOC)) {
if ($dbfilerow['filename'] == "") {
continue;
}
Expand All @@ -148,7 +148,7 @@ function edit_input(id) {
print "<option value=\"{$dbfilerow['id']}\">{$dbfilerow['filename']}</option>\n";
}
}
mysql_free_result($result);
$result->closeCursor();
?>
</select>
</div>
Expand Down
10 changes: 5 additions & 5 deletions web/db/BETY/inputs_show.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
$query="SELECT dbfiles.id, concat(machines.hostname, ':', dbfiles.file_path, '/', dbfiles.file_name) as filename" .
" FROM dbfiles, machines, inputs" .
" WHERE inputs.id=$id AND dbfiles.container_id=inputs.id AND dbfiles.container_type='Input' AND machines.id=dbfiles.machine_id;";
$result = mysql_query($query, $db_connection);
$result = $pdo->query($query, $db_connection);
if (!$result) {
die("Invalid query [$query] " . mysql_error($db_connection));
die("Invalid query [$query] " . $pdo->errorInfo($db_connection));
}
if (mysql_num_rows($result) > 0) {
if ($result->fetchColumn() > 0) {
?>
<script type="text/javascript">
function show_input(id) {
Expand All @@ -49,10 +49,10 @@ function show_input(id) {
<div class="val">
<select id="file">
<?php
while($dbfilerow = @mysql_fetch_assoc($result)) {
while($dbfilerow = @$result->fetch(PDO::FETCH_ASSOC)) {
print "<option value=\"{$dbfilerow['id']}\">{$dbfilerow['filename']}</option>\n";
}
mysql_free_result($result);
$result->closeCursor();
?>
</select>
</div>
Expand Down
Loading

0 comments on commit 8c4346d

Please sign in to comment.