1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
function query($query)
{
// For reg expressions
$query = trim($query);
$return_value = 0;
// Flush cached values..
$this->flush();
// Log how the function was called
$this->func_call = "\$db->query(\"$query\")";
// Keep track of the last query for debug..
$this->last_query = $query;
// Parses the query and returns a statement..
if ( ! $stmt = OCIParse($this->dbh, $query))
{
$this->print_error("Last Query",$query);
}
// Execut the query..
else if ( ! $this->result = oci_execute($stmt))
{
$this->print_error("Last Query",$query);
}
$this->num_queries++;
// If query was an insert
if ( preg_match('/^(insert|delete|update|create)\s+/i', $query) )
{
// num afected rows
$return_value = $this->rows_affected = OCIRowCount($stmt);
}
// If query was a select
else
{
// Get column information
if ( $num_cols = @OCINumCols($stmt) )
{
// Fetch the column meta data
for ( $i = 1; $i <= $num_cols; $i++ )
{
$this->col_info[($i-1)]->name = OCIColumnName($stmt,$i);
$this->col_info[($i-1)]->type = OCIColumnType($stmt,$i);
$this->col_info[($i-1)]->size = OCIColumnSize($stmt,$i);
}
}
// If there are any results then get them
if ($this->num_rows = @OCIFetchStatement($stmt,$results))
{
// Convert results into object orientated results..
// Due to Oracle strange return structure - loop through columns
foreach ( $results as $col_title => $col_contents )
{
$row_num=0;
// then - loop through rows
foreach ( $col_contents as $col_content )
{
$this->last_result[$row_num]->{$col_title} = $col_content;
$row_num++;
}
}
}
// num result rows
$return_value = $this->num_rows;
}
// If debug ALL queries
$this->trace || $this->debug_all ? $this->debug() : null ;
return $return_value;
} |
Partager