Fix issues #5.

This commit is contained in:
nearwood 2015-02-08 16:34:00 -05:00
parent ebb3a39ac8
commit a911158fe9
2 changed files with 22 additions and 12 deletions

View File

@ -24,7 +24,7 @@ require('header.php');
</form>
</div>
<?php
$results = getAll();
$results = browseAll();
$numResults = count($results);
//echo '<div class="debug">'; var_export($results); echo '</div>';

32
db.php
View File

@ -1,21 +1,31 @@
<?php
require "config.php";
/**
* Connect to the DB, reusing any existing connection
*/
function connect()
{
//TODO Reuse connection
$db = null;
try
global $db;
if (isset($db) && $db instanceof PDO)
{
if (DEBUG) echo '<div class="debug">' . "mysql:dbname=" . DB_NAME . ";host=" . DB_HOST . "," . DB_USERNAME . ", [****]" . '</div>';
$db = new PDO("mysql:dbname=" . DB_NAME . ";host=" . DB_HOST, DB_USERNAME, DB_PASSWORD);
if (DEBUG) echo '<div class="debug">Reusing DB connection.</div>';
}
catch (PDOException $e)
else
{
echo '<div class="error">Error connecting to database.</div>';
dbError($e);
$db = null; //Redundant.
try
{
if (DEBUG) echo '<div class="debug">Connecting to DB: ' . "mysql:dbname=" . DB_NAME . ";host=" . DB_HOST . "," . DB_USERNAME . ", [****]" . '</div>';
$db = new PDO("mysql:dbname=" . DB_NAME . ";host=" . DB_HOST, DB_USERNAME, DB_PASSWORD);
//Persistent connection:
//$db = new PDO("mysql:dbname=" . DB_NAME . ";host=" . DB_HOST, DB_USERNAME, DB_PASSWORD, array(PDO::ATTR_PERSISTENT => true);
}
catch (PDOException $e)
{
echo '<div class="error">Error connecting to database.</div>';
dbError($e);
$db = null; //Redundant.
}
}
return $db;
@ -289,7 +299,7 @@ function getMSQ($id)
//TODO Rename?
//TODO Pagination
function getAll()
function browseAll()
{
$db = connect();
if ($db == null) return null;