Skip to content

Commit

Permalink
Added docblock documentation for changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenrnl committed May 2, 2014
1 parent 4dbfc20 commit d0a876d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
12 changes: 12 additions & 0 deletions php/UnitTests/PDOdatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class PDOdatabaseTest extends ZophDataBaseTestCase {
/**
* Create queries
* @dataProvider getQueries();
* @param string Table to run query on
* @param array Fields to query
* @param string Expected SQL query
*/
public function testCreateQuery($table, $fields, $exp_sql) {
if(is_array($fields)) {
Expand All @@ -43,6 +46,9 @@ public function testCreateQuery($table, $fields, $exp_sql) {
/**
* Run queries
* @dataProvider getQueries();
* @param string Table to run query on
* @param array Fields to query
* @param string Expected SQL query
*/
public function testRunQuery($table, $fields, $exp_sql) {
// not used
Expand All @@ -55,6 +61,9 @@ public function testRunQuery($table, $fields, $exp_sql) {
$this->assertInstanceOf("PDOStatement", $result);
}

/**
* Test a query with a WHERE clause
*/
public function testQueryWithClause() {

$qry=new query("photos");
Expand Down Expand Up @@ -86,6 +95,9 @@ public function testQueryWithClause() {

}

/**
* Provide queries to use as test input
*/
public function getQueries() {
return array(
array("photos", array("photo_id"), "SELECT zoph_photos.photo_id FROM zoph_photos;"),
Expand Down
12 changes: 11 additions & 1 deletion php/classes/db.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@
* @author Jeroen Roos
*/
class db {

/** @var holds connection */
private static $connection=false;

/** @var database host */
private static $dbhost;
/** @var database name */
private static $dbname;
/** @var database user */
private static $dbuser;
/** @var database password */
private static $dbpass;
/** @var table prefix */
private static $dbprefix;

/**
Expand Down Expand Up @@ -91,6 +96,7 @@ public static function getPrefix() {

/**
* Connect to database
* @param string PDO DSN
*/
private static function connect($dsn=null) {
if(!$dsn) {
Expand All @@ -111,6 +117,10 @@ private static function getDSN() {
return $dsn;
}

/**
* Run a query
* @param query Query to run
*/
public static function query(query $query) {
$db=self::getHandle();
return $db->query($query);
Expand Down
22 changes: 22 additions & 0 deletions php/classes/query.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,20 @@
*/
class query {

/** @var string db table to query */
private $table;
/** @var array fields to query */
private $fields=null;
/** @var array parameters for prepared queries */
private $params=null;
/** @var string WHERE clause */
private $clause=null;

/**
* Create new query
* @param string Table to query
* @param array Fields to query
*/
public function __construct($table, array $fields=null) {
$table=db::getPrefix() . $table;
if(is_array($fields)) {
Expand All @@ -45,14 +54,27 @@ public function __construct($table, array $fields=null) {

}

/**
* Add a parameter for a prepared query
* @param string Parameter name
* @param string Parameter value
*/
public function addParam($param, $value) {
$this->params[$param]=$value;
}

/**
* Add a WHERE clause to the query
* @param clause WHERE clause
*/
public function where(clause $clause) {
$this->clause=$clause;
}

/**
* Create query
* @return string SQL query
*/
public function __toString() {
$sql = "SELECT ";

Expand Down

0 comments on commit d0a876d

Please sign in to comment.