conn = $conn; } function reset(){ $this->query = ''; } /** * 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 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 = @mysql_query($this->query, $this->conn))) { if($showerror) { $errormsg = "Erro no MYSQL:
    ".mysql_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 MySQL: 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(); $num_rows = mysql_num_rows($result); $return = array(); for($i=0; $i< $num_rows; $i++){ array_push($return, mysql_fetch_array($result, MYSQL_ASSOC)); } return $return; } function vt_recordset3($sql, $chaves = null){ if(is_null($sql)) return false; $this->query = "$sql"; //die($this->query); $result = $this->execute(); $num_rows = mysql_num_rows($result); $return = array(); //echo "
    ";
    		//echo "::".mysql_num_rows($result);
    		while($row = mysql_fetch_array($result, MYSQL_ASSOC)){//for($i=0; $i< $num_rows; $i++){
    			if(is_array($chaves)){
    				$tmpreturn = &$return;
    				$tmpreturn2;
    				for($i=0; $i< sizeof($chaves); $i++){
    					if($row[$chaves[$i]]){
    							$tmpreturn2 = &$tmpreturn;
    							$tmpreturn = &$tmpreturn[$row[$chaves[$i]]];
    							$indice = $row[$chaves[$i]];
    					}
    					if($i==(sizeof($chaves)-1))
    						$tmpreturn2[$indice] = $row;
    					
    				}
    			}/*if(!is_null($chave)){
    				$row = mysql_fetch_array($result, MYSQL_ASSOC);
    				//echo "$chave".$row[$chave]."=";
    				//print_r($row);
    				$return[$row[$chave]] = $row;
    			}*/
    			else
    				array_push($return, $row);
    			
    			//echo "
    ";
    			//print_r($row);
    			//echo "\n\n\n\n\n\n\n\n\n
    "; } //die(); //echo "
    "; return $return; } function count($table, $sql=""){ if(!empty($table)){ $this->query = "SELECT * FROM $table WHERE $sql"; //die($this->query); $qid = $this->execute() or die("
  • ERRO NO MySQL:".mysql_error()); return mysql_num_rows($qid); }else return 0; } } ?>