connected = 1; if (function_exists('mysql_connect')) { //error_log("class.mysql:Connect: "."Conectado"." \n", 3, "/var/www/html/error.log"); //error_log("class.mysql:Connect: ".$this->db_user." \n", 3, "/var/www/html/error.log"); //error_log("class.mysql:Connect: ".$this->db_host." \n", 3, "/var/www/html/error.log"); $this->db = mysql_connect($this->db_host, $this->db_user, $this->db_pass) or $this->connected=0; } else { $this->db = mysqli_connect($this->db_host, $this->db_user, $this->db_pass) or $this->connected=0; //error_log("class.mysql:Connect: "."No conectado"." \n", 3, "/var/www/html/error.log"); } $this->setdb(); mysql_query("SET NAMES 'utf8'"); } function disconnect() { // // Connects to the SQL server and sets the active database. // $this->connected = 0; if (function_exists('mysql_connect')) { $this->db = mysql_close($this->db) or $this->connected=1; } else { $this->db = mysqli_close($this->db) or $this->connected=1; } } function setdb($new_db='') { // // Sets the active database. If new_db is specified, the active database is set to it. // If not, it uses the current this->db_name. // if ($new_db) { $this->db_name = $new_db; } if (function_exists('mysql_connect')) { if ($this->connected) { mysql_select_db($this->db_name,$this->db); } } else { if ($this->connected) { mysqli_select_db($this->db,$this->db_name); } } } function seterror($s) { // // Called internally to set the error message generated by a failed method call. // trigger_error ("SQL Error: " . $s, E_USER_ERROR); $this->db_error = $s; } function insertquery($sql) { // // Wrapper for mysql_query(), for use with "INSERT INTO" queries. // // Returns the ID of the new row on success, or FALSE on error. // if (function_exists('mysql_connect')) { $result = @mysql_query($sql,$this->db) or $this->seterror("Could not execute query: $sql: ".mysql_error($this->db)); if ($result) { $this->affected = mysql_affected_rows(); return mysql_insert_id($this->db); } else { return $result; } } else { $result = @mysqli_query($this->db, $sql) or $this->seterror("Could not execute query: $sql: ".mysqli_error($this->db)); if ($result) { $this->affected = mysqli_affected_rows($this->db); return mysqli_insert_id($this->db); } else { return $result; } } } function miscquery($sql) { // // Wrapper for mysql_query(), for use with miscellaneous queries. // // Basically just for consistency with insertquery and() selectquery(). // Returns the TRUE on success, FALSE on failure. // if (function_exists('mysql_connect')) { $result = (@mysql_query($sql,$this->db) or $this->seterror("Could not execute query: $sql: ".mysql_error($this->db))); $this->affected = mysql_affected_rows(); return $result; } else { $result = (@mysqli_query($this->db,$sql) or $this->seterror("Could not execute query: $sql: ".mysqli_error($this->db))); $this->affected = mysqli_affected_rows($this->db); return $result; } } function selectquery($sql) { // // Wrapper for mysql_query(), for use with SELECT queries. // // Returns the first result row on success, or FALSE on failure. // Subsequent rows may be retrieved using selectnext() or nextresult(). // if (function_exists('mysql_connect')) { $result = @mysql_query($sql,$this->db) or $this->seterror("Could not execute query: $sql: " . mysql_error($this->db)); if ($result) { //error_log("class.mysql:Query: ".$sql." \n", 3, "../error.log"); //error_log("class.mysql:Query: ".$result." \n", 3, "../error.log"); $this->db_result = $result; $this->results = mysql_num_rows($result); return $this->selectnext(); } else { //error_log("class.mysql:Query: ".$sql." \n", 3, "../error.log"); return $result; } } else { $result = @mysqli_query($this->db,$sql) or $this->seterror("Could not execute query: $sql: " . mysqli_error($this->db)); if ($result) { $this->db_result = $result; $this->results = mysqli_num_rows($result); return $this->selectnext(); } else { return $result; } } } function selectnext() { // // Wrapper for mysql_fetch_array(). // // Automatically strips escape characters (slashes) from string-type elements // prior to returning. // Returns the next result row on success, or FALSE on failure. // if (function_exists('mysql_connect')) { if ($myrow = mysql_fetch_array($this->db_result)) { $k = array_keys($myrow); for ($i=0; $idb_result)) { $k = array_keys($myrow); for ($i=0; $iselectquery($sql); if (!is_array($res)) { return false; } while (is_array($res)) { $output[] = $res; $res = $this->selectnext(); } return $output; } function selcount($sql) { // // Count records if (function_exists('mysql_connect')) { $result = @mysql_query($sql,$this->db) or $this->seterror("Could not execute query: $sql: " . mysql_error($this->db)); if ($result) { $num_rows = mysql_num_rows($result); return $num_rows; }} } function nextresult() { // // same as selectnext() // return $this->selectnext(); } } } /* __CLASS_MYSQL_INC */ ?>