session = odbc_pconnect($db, $user, $password); $this->debug = $debug; } function prepare ($query) { return new STH($this, $this->session, $query, $this->debug); } function autocommit ($value) { return odbc_autocommit ($this->session, $value); } function commit () { return odbc_commit($this->session); } function rollback () { return odbc_rollback($this->session); } function quote ($str) { if (get_magic_quotes_gpc()) { $str = stripslashes($str); } return "'".str_replace ("'", "''", $str)."'"; } function insert_id ($sequence) { $sth = new STH($this, $this->session, "SELECT $sequence.CURRVAL FROM DUAL", $this->mode, $this->debug); $sth->execute(); list($res) = $sth->fetchrow_array(); return $res; } } class STH { var $query; var $statement; var $debug; var $dbi; var $placeholders; function STH (&$dbi, &$session, $query, $debug) { $this->dbi = &$dbi; $this->query = $query; $this->debug = $debug; $this->session = &$session; $this->statement = odbc_prepare($this->session, $this->query); return $this->statement; } function execute () { global $SERVER_NAME; $numargs = func_num_args(); $arg_list = func_get_args(); $parms = array(); for ($i = 0; $i < $numargs; $i++) { if (is_array($arg_list[$i])) { while (list($dummy,$parm) = each ($arg_list[$i])) { array_push($parms, $parm); } } else { array_push($parms,$arg_list[$i]); } } if ($this->debug) { // Log the query $fd = fopen("/tmp/dbi.$SERVER_NAME.log", "a") or die ("Couldn't append to file"); fputs($fd, date("M d H:i:s",time()).": ".$query."\nParameters: ".join(',',$parms)."\n==================\n"); fclose($fd); } if (!odbc_execute($this->statement, $parms)) { print "
Could not execute SQL query: \"".$query."\"
"; exit; } } function fetchrow_array () { $res = array(); odbc_fetch_into($this->statement, $res); return $res; } function fetchrow_hash () { $res = array(); odbc_fetch_into($this->statement, $res); $res2 = array(); for ($i = 0; $i < sizeof($res); ++$i) { $res2[odbc_field_name($this->statement, $i + 1)] = $res[$i]; } return $res2; } function rows () { return odbc_num_rows ($this->statement); } function finish () { odbc_free_result($this->statement); } } ?>