Commit f4925894 authored by Jeffrey Way's avatar Jeffrey Way

More bug fixes

parent 94c81556
...@@ -37,7 +37,7 @@ class MysqlDB { ...@@ -37,7 +37,7 @@ class MysqlDB {
*/ */
public function get($tableName, $numRows = NULL) public function get($tableName, $numRows = NULL)
{ {
$this->_crudType = 'read';
$this->_query = "SELECT * FROM $tableName"; $this->_query = "SELECT * FROM $tableName";
$stmt = $this->_buildQuery($numRows); $stmt = $this->_buildQuery($numRows);
$stmt->execute(); $stmt->execute();
...@@ -55,6 +55,7 @@ class MysqlDB { ...@@ -55,6 +55,7 @@ class MysqlDB {
*/ */
public function insert($tableName, $insertData) public function insert($tableName, $insertData)
{ {
$this->_crudType = 'insert';
$this->_query = "INSERT into $tableName"; $this->_query = "INSERT into $tableName";
$stmt = $this->_buildQuery(NULL, $insertData); $stmt = $this->_buildQuery(NULL, $insertData);
$stmt->execute(); $stmt->execute();
...@@ -72,6 +73,7 @@ class MysqlDB { ...@@ -72,6 +73,7 @@ class MysqlDB {
*/ */
public function update($tableName, $tableData) public function update($tableName, $tableData)
{ {
$this->_crudType = 'update';
$this->_query = "UPDATE $tableName SET "; $this->_query = "UPDATE $tableName SET ";
$stmt = $this->_buildQuery(NULL, $tableData); $stmt = $this->_buildQuery(NULL, $tableData);
$stmt->execute(); $stmt->execute();
...@@ -85,7 +87,9 @@ class MysqlDB { ...@@ -85,7 +87,9 @@ class MysqlDB {
* @param string $tableName The name of the database table to work with. * @param string $tableName The name of the database table to work with.
* @return boolean Indicates success. 0 or 1. * @return boolean Indicates success. 0 or 1.
*/ */
public function delete($tableName) { public function delete($tableName)
{
$this->_crudType = 'delete';
$this->_query = "DELETE FROM $tableName"; $this->_query = "DELETE FROM $tableName";
$stmt = $this->_buildQuery(); $stmt = $this->_buildQuery();
...@@ -162,9 +166,7 @@ class MysqlDB { ...@@ -162,9 +166,7 @@ class MysqlDB {
// and create the SQL query, accordingly. // and create the SQL query, accordingly.
if ($hasTableData) { if ($hasTableData) {
$i = 1; $i = 1;
$pos = strpos($this->_query, 'UPDATE'); if ( $this->_crudType == 'update' ) {
if ( $pos !== false) {
$this->_crudType = 'update';
foreach ($tableData as $prop => $value) { foreach ($tableData as $prop => $value) {
// determines what data type the item is, for binding purposes. // determines what data type the item is, for binding purposes.
$this->_paramTypeList .= $this->_determineType($value); $this->_paramTypeList .= $this->_determineType($value);
...@@ -186,10 +188,8 @@ class MysqlDB { ...@@ -186,10 +188,8 @@ class MysqlDB {
} }
} }
// Determine if is INSERT query // Determine if is INSERT query
if ($hasTableData && !isset($this->_crudType)) { if ($hasTableData && $this->_crudType == 'insert') {
$pos = strpos($this->_query, 'INSERT'); if ( $this->_crudType == 'insert' ) {
if ($pos !== false) {
//is insert statement
$keys = array_keys($tableData); $keys = array_keys($tableData);
$values = array_values($tableData); $values = array_values($tableData);
$num = count($keys); $num = count($keys);
...@@ -270,6 +270,7 @@ class MysqlDB { ...@@ -270,6 +270,7 @@ class MysqlDB {
*/ */
protected function _prepareQuery() protected function _prepareQuery()
{ {
echo $this->_query;
if (!$stmt = $this->_mysql->prepare($this->_query)) { if (!$stmt = $this->_mysql->prepare($this->_query)) {
trigger_error("Problem preparing query", E_USER_ERROR); trigger_error("Problem preparing query", E_USER_ERROR);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment