/** * Execute the specified SQL/commands on the database. * * @param string $sql The SQL/command to send to the database. * * @return mixed string or array of returned data, or false on failure */ public function execute($sql) { $output = false; // Check/execute macros foreach ($this->_macros[$this->_db_type] as $pattern => $replacement) { $c = 0; $sql = str_replace($pattern, $replacement, $sql, $c); if ($c > 0) { break; } } // Strip semicolon from end if its Oracle if ($this->_db_type == 'oci') { $sql = mb_substr($sql, 0, mb_strlen($sql) - 1); } // Check what kind of query it is $query_type = $this->_getQueryType($sql); switch ($query_type) { case "SELECT": $output = MatrixDAL::executeSqlAssoc($sql); break; case "UPDATE": case "INSERT": $rows_affected = MatrixDAL::executeSql($sql); $output = $query_type . " " . $rows_affected; break; case "BEGIN": /* There is no return bool code, but according to PHP docs an exception will be thrown if the DB doesn't support transactions */ MatrixDAL::beginTransaction(); $output = $query_type; break; case "ROLLBACK": MatrixDAL::rollBack(); $output = $query_type; break; case "COMMIT": MatrixDAL::commit(); $output = $query_type; break; default: //echo "WARNING: Query type not recognised.\n"; $output = MatrixDAL::executeSqlAssoc($sql); break; } return $output; }