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
 /**
  * Returns the server version string.
  * 
  * @return string
  */
 function server_version()
 {
     $result = $this->query('SELECT @@version AS SERVER_VERSION');
     $version = sybase_result($result, 0, 'SERVER_VERSION');
     if (isset($version)) {
         return $version;
     }
 }
예제 #3
0
 function metadata($table)
 {
     $count = 0;
     $id = 0;
     $res = array();
     $this->connect();
     $result = $this->query("exec sp_columns {$table}");
     if ($result < 0) {
         $this->Errno = 1;
         $this->Error = "Metadata query failed";
         $this->halt("Metadata query failed.");
     }
     $count = sybase_num_rows($result);
     for ($i = 0; $i < $count; $i++) {
         $res[$i]["table"] = $table;
         $res[$i]["name"] = sybase_result($result, $i, "COLUMN_NAME");
         $res[$i]["type"] = sybase_result($result, $i, "TYPE_NAME");
         $res[$i]["len"] = sybase_result($result, $i, "LENGTH");
         $res[$i]["position"] = sybase_result($result, $i, "ORDINAL_POSITION");
         $res[$i]["flags"] = sybase_result($result, $i, "REMARKS");
     }
 }
 function Insert($query)
 {
     $this->res = 0;
     $this->oid = 0;
     $this->cur = -1;
     $this->vcur = -1;
     $this->Record = array();
     if ($this->conn) {
         $this->res = sybase_query($query, $this->conn);
         if ($this->res) {
             $oidRes = sybase_query('SELECT @@identity', $this->conn);
             if ($oidRes) {
                 $this->oid = sybase_result($oidRes, 0, 0);
             } else {
                 trigger_error('Could not retrieve @@identity of newly inserted record!!  Query: ' . $query);
             }
             return $this->oid;
         } else {
             trigger_error("Error executing query: {$query}");
             return -1;
         }
     } else {
         trigger_error('No connection!');
         return -1;
     }
 }