function query($query)
 {
     //if flag to convert query from MySql syntax to Sybase syntax is true
     //convert the query
     if ($this->convertMySqlTosybaseQuery == true) {
         $query = $this->ConvertMySqlTosybase($query);
     }
     // Initialise return
     $return_val = 0;
     // Flush cached values..
     $this->flush();
     // For reg expressions
     $query = trim($query);
     // Log how the function was called
     $this->func_call = "\$db->query(\"{$query}\")";
     // Keep track of the last query for debug..
     $this->last_query = $query;
     // Count how many queries there have been
     $this->num_queries++;
     // Use core file cache function
     if ($cache = $this->get_cache($query)) {
         return $cache;
     }
     // If there is no existing database connection then try to connect
     if (!isset($this->dbh) || !$this->dbh) {
         $this->connect($this->dbuser, $this->dbpassword, $this->dbhost);
         $this->select($this->dbname);
     }
     // Perform the query via std sybase_query function..
     $this->result = @sybase_query($query);
     // If there is an error then take note of it..
     if ($this->result == false) {
         $get_errorcodeSql = "SELECT @@ERROR as errorcode";
         $error_res = @sybase_query($get_errorcodeSql, $this->dbh);
         $errorCode = @sybase_result($error_res, 0, "errorcode");
         $get_errorMessageSql = "SELECT severity as errorSeverity, text as errorText FROM sys.messages  WHERE message_id = " . $errorCode;
         $errormessage_res = @sybase_query($get_errorMessageSql, $this->dbh);
         if ($errormessage_res) {
             $errorMessage_Row = @sybase_fetch_row($errormessage_res);
             $errorSeverity = $errorMessage_Row[0];
             $errorMessage = $errorMessage_Row[1];
         }
         $sqlError = "ErrorCode: " . $errorCode . " ### Error Severity: " . $errorSeverity . " ### Error Message: " . $errorMessage . " ### Query: " . $query;
         $is_insert = true;
         $this->register_error($sqlError);
         $this->show_errors ? trigger_error($sqlError, E_USER_WARNING) : null;
         return false;
     }
     // Query was an insert, delete, update, replace
     $is_insert = false;
     if (preg_match("/^(insert|delete|update|replace)\\s+/i", $query)) {
         $this->rows_affected = @sybase_rows_affected($this->dbh);
         // Take note of the insert_id
         if (preg_match("/^(insert|replace)\\s+/i", $query)) {
             $identityresultset = @sybase_query("select SCOPE_IDENTITY()");
             if ($identityresultset != false) {
                 $identityrow = @sybase_fetch_row($identityresultset);
                 $this->insert_id = $identityrow[0];
             }
         }
         // Return number of rows affected
         $return_val = $this->rows_affected;
     } else {
         // Take note of column info
         $i = 0;
         while ($i < @sybase_num_fields($this->result)) {
             $this->col_info[$i] = @sybase_fetch_field($this->result);
             $i++;
         }
         // Store Query Results
         $num_rows = 0;
         while ($row = @sybase_fetch_object($this->result)) {
             // Store relults as an objects within main array
             $this->last_result[$num_rows] = $row;
             $num_rows++;
         }
         @sybase_free_result($this->result);
         // Log number of rows the query returned
         $this->num_rows = $num_rows;
         // Return number of rows selected
         $return_val = $this->num_rows;
     }
     // disk caching of queries
     $this->store_cache($query, $is_insert);
     // If debug ALL queries
     $this->trace || $this->debug_all ? $this->debug() : null;
     return $return_val;
 }
예제 #2
0
function sql_fetch_object(&$res, $nr = 0)
{
    global $dbtype;
    switch ($dbtype) {
        case "MySQL":
            $row = mysql_fetch_object($res);
            if ($row) {
                return $row;
            } else {
                return false;
            }
            break;
        case "mSQL":
            $row = msql_fetch_object($res);
            if ($row) {
                return $row;
            } else {
                return false;
            }
            break;
        case "postgres":
        case "postgres_local":
            if ($res->get_total_rows() > $res->get_fetched_rows()) {
                $row = pg_fetch_object($res->get_result(), $res->get_fetched_rows());
                $res->increment_fetched_rows();
                if ($row) {
                    return $row;
                } else {
                    return false;
                }
            } else {
                return false;
            }
            break;
        case "ODBC":
            $result = odbc_fetch_row($res, $nr);
            if (!$result) {
                return false;
            }
            $nf = odbc_num_fields($res);
            /* Field numbering starts at 1 */
            for ($count = 1; $count < $nf + 1; $count++) {
                $field_name = odbc_field_name($res, $count);
                $field_value = odbc_result($res, $field_name);
                $row->{$field_name} = $field_value;
            }
            return $row;
            break;
        case "ODBC_Adabas":
            $result = odbc_fetch_row($res, $nr);
            if (!$result) {
                return false;
            }
            $nf = count($result) + 2;
            /* Field numbering starts at 1 */
            for ($count = 1; $count < $nf; $count++) {
                $field_name = odbc_field_name($res, $count);
                $field_value = odbc_result($res, $field_name);
                $row->{$field_name} = $field_value;
            }
            return $row;
            break;
        case "Interbase":
            $orow = ibase_fetch_object($res);
            if ($orow) {
                $arow = get_object_vars($orow);
                while (list($name, $key) = each($arow)) {
                    $name = strtolower($name);
                    $row->{$name} = $key;
                }
                return $row;
            } else {
                return false;
            }
            break;
        case "Sybase":
            $row = sybase_fetch_object($res);
            return $row;
            break;
    }
}
예제 #3
0
 /**
  * Fetch a result row as an object
  *
  * @param   mixed $result
  * @return  mixed
  */
 function fetchObject($result)
 {
     return sybase_fetch_object($result);
 }