f_a=& $this->fetch_array; $this->f_r=& $this->fetch_rows; $this->f_as=& $this->fetch_assoc; $this->n_r=& $this->numero_resultados; $this->U_i=& $this->Ultimo_insert; } public function connstring($direccion, $user, $pass, $base){ $this->conn_string=array($direccion, $user, $pass, $base); } public function Conectar(){ $this->linker= mysql_connect($this->conn_string[0],$this->conn_string[1],$this->conn_string[2]); if(!$this->linker){ die("ERROR Conectando a la base"); } mysql_select_db($this->conn_string[3], $this->linker); mysql_query("SET NAMES 'UTF8'",$this->linker); } public function desConectar(){ // mysql_close($this->linker); } public function resultado($fetch){ switch($fetch){ case 1: $this->fetch_array=array(); while($F=mysql_fetch_array($this->query)){ $this->fetch_array[]=$F; }; break; case 2: $this->fetch_rows=array(); while($F=mysql_fetch_row($this->query)){ $this->fetch_rows[]=$F; }; break; case 3: $this->fetch_assoc=array(); while($F=mysql_fetch_assoc($this->query)){ $this->fetch_assoc[]=$F; }; break; case 4: $this->fetch_array=array(); $this->fetch_rows=array(); $this->fetch_assoc=array(); break; } } public function test($fetch){ $this->Conectar(); $this->sql="SELECT * FROM pais"; $this->query=mysql_query($this->sql,$this->linker) or $this->error(); $this->numero_resultados=mysql_num_rows($this->query); if($this->numero_resultados>0){ $this->resultado($fetch); } $this->desConectar(); } public function consult_base($sql,$fetch){ $this->sql=trim($sql); $this->Conectar(); $this->query=mysql_query($this->sql,$this->linker) or $this->error(); $this->numero_resultados=mysql_num_rows($this->query); if($this->numero_resultados>0){ $this->resultado($fetch); } $this->desConectar(); } public function c($sql,$fetch=3){ $this->consult($sql,$fetch); } public function consult($sql,$fetch){ $sql=trim(str_replace(array("\n","\t","\r")," ",$sql)); $this->sql=$sql; /* if(!$sin){ $resto=str_ireplace('from ',"",stristr($sql, 'from')); $this->tabla=trim(substr($resto,0,strpos($resto," "))); if(!stristr($sql,'order') && $this->tabla!="" && !stristr($sql,'information_schema')){ $this->sql=$sql." ORDER BY ".$this->tabla.".".$this->primer_row_tabla()." asc"; }/// } */ $this->Conectar(); $this->query=mysql_query($this->sql,$this->linker) or $this->error(); $this->numero_resultados=mysql_num_rows($this->query); if($this->numero_resultados>0){ $this->resultado($fetch); }else{$this->resultado(4);} $this->desConectar(); } public function del($sql){ $sql=trim(str_replace(array("\n","\t","\r")," ",$sql)); $this->sql=$sql; $this->Conectar(); $this->query=mysql_query($this->sql,$this->linker) or $this->error(); $this->desConectar(); } public function insert($sql,$tabla){ $this->Conectar(); $this->sql=$sql; //var_dump($this->sql); $this->query=mysql_query($this->sql,$this->linker) or $this->error(); if (!$this->query) { echo "query did not execute"; } if($tabla!=""){ $this->consult("SELECT column_name FROM information_schema.columns WHERE table_name = '".$tabla."' limit 1",2,1); $id=$this->fetch_rows[0][0]; //var_dump($this->fetch_rows); $this->consult("SELECT ".$id." FROM ".$tabla." order by ".$tabla." desc limit 1",2); //var_dump($this->sql); //var_dump($this->fetch_rows); $this->Ultimo_insert=$this->fetch_rows[0][0]; } $this->desConectar(); } public function max_id($tabla){ $this->Conectar(); if($tabla!=""){ $this->tabla=$tabla; $id=$this->primer_row_tabla(); //var_dump($this->fetch_rows); $this->consult("SELECT ".$id." FROM ".$tabla." order by ".$tabla." desc limit 1",2); //var_dump($this->sql); //var_dump($this->fetch_rows); $id_max=$this->fetch_rows[0][0]; if(!is_numeric($id_max)){ $id_max='1'; } } $this->desConectar(); return $id_max; } public function primer_row_tabla(){ $sql="SELECT column_name FROM information_schema.columns WHERE table_name = '".$this->tabla."' limit 1"; $this->consult_base($sql,2); $id=$this->fetch_rows[0][0]; return $id; } public function error(){ die( mysql_error($this->linker)."
"); } } ?>