conn = $conn; } /** * Atenção, setar $this->conn e$this->query antes de usar o execute. * * @param bool $showerror * @param bool $debug * @return "in error, 0, else resource ID" */ function reset(){ unset($this->query); } function execute($showerror = true, $debug = false) { //echo "
  • ".$this->query; //return true; if(!isset($this->query) || !($this->conn)){ return 0; // Error in connection or SQL clausule. } if (!($ok = odbc_exec($this->conn, $this->query))) { if($showerror) { $errormsg = "Erro no ODBC:
    ".odbc_error()."
    \n"; if($debug) $errormsg.=":::::::SQL::::::::".$this->query; die($errormsg); } } return $ok; } /** * retorna um vetor com os resultados da query. * * @param string $operation "INSERT", "SELECT", "DELETE", "UPDATE" (UTILIZAR CAIXA ALTA) * @param vetor $fields * @param vetor $tables * @param string $sql somente a query, sem values, where, etc. * @return vetor */ function vt_recordset($fields, $tables, $sql){ //die("sizeof".sizeof($tables)); //die("query".$sql); if(sizeof($tables)==0) die("
  • Erro no ODBC: erro na sintaxe da query.SELECT $fields from $tables where $sql"); $this->query = "SELECT "; for($i=0; $i< sizeof($fields); $i++){ if($i != 0) $this->query .= ","; $this->query .= " ".$fields[$i]; } $this->query .= " FROM "; for($i=0; $i< sizeof($tables); $i++){ if($i != 0) $this->query .= ","; $this->query .= " ".$tables[$i]; } if(!empty($sql)) $this->query .= " $sql"; //die($this->query); $result = $this->execute(); $return = array(); while($row = odbc_fetch_array($result)){ array_push($return, $row); } odbc_free_result($result); return $return; } function vt_recordset3($sql, $chaves=null){ if(empty($sql)) return false; else $this->query = $sql; //die($this->query); $result = $this->execute(); $return = array(); while($row = odbc_fetch_array($result)){ if(is_array($chaves)){ $tmpreturn = &$return; for($i=0; $i< sizeof($chaves); $i++){ if($i==(sizeof($chaves)-1)) $tmpreturn[$row[$chaves[$i]]] = $row; else{ $tmpreturn = &$tmpreturn[$row[$chaves[$i]]]; if(!is_array($tmpreturn)) $tmpreturn = array(); } } } else array_push($return, $row); } odbc_free_result($result); return $return; } function count($table, $sql=""){ if(!empty($table)){ $this->query = "SELECT COUNT(*) as 'numrows' FROM $table WHERE $sql"; //die($this->query); $qid = $this->execute() or die("
  • ERRO NO ODBC:".odbc_error()); $tot = odbc_fetch_array($qid); return $tot['numrows']; }else return 0; } } ?>