Uso una clase para tratar con bases de datos, y la uso en muchisimas aplicaciones, al migrar a un nuevo servidor me he dado cuenta que esa funcion no está funcionando correctamente. He leido que se han hecho modificaciones en cuanto al tratamiento de clases. Alguien me podria ayudar a modificar, si no es mucho trabajo porque a lo mejor conviene mas cambiar las aplicaciones, la clase? El codigo es el siguiente
Código PHP:
<?php
class db{
// global variables
var $mySQLserver;
var $mySQLuser;
var $mySQLpassword;
var $mySQLdefaultdb;
var $mySQLaccess;
var $mySQLresult;
var $mySQLrows;
var $mySQLerror;
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Connect($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb){
/*
# Connect to mySQL server and select database
#
# - parameters #1: string $mySQLserver, mySQL server
# - parameters #2: string $mySQLuser, mySQL username
# - parameters #3: string $mySQLpassword, mySQL password
# - parameters #4: string mySQLdefaultdb, mySQL default database
# - return error if encountered
# - scope public
*/
$this->mySQLserver = $mySQLserver;
$this->mySQLuser = $mySQLuser;
$this->mySQLpassword = $mySQLpassword;
$this->mySQLdefaultdb = $mySQLdefaultdb;
$temp = $this->mySQLerror;
$this->mySQLerror = FALSE;
$this->mySQL_access = @mysql_connect($this->mySQLserver, $this->mySQLuser, $this->mySQLpassword);
@mysql_select_db($this->mySQLdefaultdb);
$this->dbError("dbConnect/SelectDB");
return $this->mySQLerror = $temp;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Select($table, $fields="*", $arg="", $mode="default"){
/*
# Select with args
#
# - parameter #1: string $table, table name
# - parameter #2: string $fields, table fields to be retrieved, default *
# - parameter #3: string $arg, query arguaments, default null
# - parameter #4: string $mode, arguament has WHERE or not, default=default (WHERE)
# - return affected rows
# - scope public
*/
$debug = false;
$debugtable = "user";
if($arg != "" && $mode=="default"){
if($debug == TRUE && $debugtable == $table){ echo "!!SELECT ".$fields." FROM ".$table." WHERE ".$arg."<br />"; }
if($this->mySQLresult = @mysql_query("SELECT ".$fields." FROM ".$table." WHERE ".$arg)){
$this->dbError("dbQuery");
return $this->db_Rows();
}else{
$this->dbError("dbQuery ($query)");
return FALSE;
}
}else if($arg != "" && $mode != "default"){
if($debug == TRUE && $debugtable == $table){ echo "@@SELECT ".$fields." FROM ".$table." ".$arg."<br />"; }
if($this->mySQLresult = @mysql_query("SELECT ".$fields." FROM ".$table." ".$arg)){
$this->dbError("dbQuery");
return $this->db_Rows();
}else{
$this->dbError("dbQuery ($query)");
return FALSE;
}
}else{
if($debug == TRUE && $debugtable == $table){ echo "SELECT ".$fields." FROM ".$table."<br />"; }
if($this->mySQLresult = @mysql_query("SELECT ".$fields." FROM ".$table)){
$this->dbError("dbQuery");
return $this->db_Rows();
}else{
$this->dbError("db_Query ($query)");
return FALSE;
}
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Insert($table, $arg){
/*
# Insert with args
#
# - parameter #1: string $table, table name
# - parameter #2: string $arg, insert string
# - return sql identifier, or error if (error reporting = on, error occured, boolean)
# - scope public
*/
// echo "INSERT INTO ".MUSER.$table." VALUES (".$arg.")";
if($result = $this->mySQLresult = @mysql_query("INSERT INTO ".$table." VALUES (".$arg.")" )){
return $result;
}else{
$this->dbError("db_Insert ($query)");
return FALSE;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Update($table, $arg){
/*
# Update with args
#
# - parameter #1: string $table, table name
# - parameter #2: string $arg, update string
# - return sql identifier, or error if (error reporting = on, error occured, boolean)
# - scope public
*/
$debug = false;
$debugtable = "stat_info";
if($debug == TRUE && $debugtable == $table){ echo "UPDATE ".$table." SET ".$arg."<br />"; }
if($result = $this->mySQLresult = @mysql_query("UPDATE ".$table." SET ".$arg)){
return $result;
}else{
$this->dbError("db_Update ($query)");
return FALSE;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Fetch(){
/*
# Retrieve table row
#
# - parameters none
# - return result array, or error if (error reporting = on, error occured, boolean)
# - scope public
*/
if($row = @mysql_fetch_array($this->mySQLresult)){
while (list($key,$val) = each($row)) {
$row[$key] = stripslashes($val);
}
$this->dbError("db_Fetch");
return $row;
}else{
$this->dbError("db_Fetch");
return FALSE;
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Count($table, $fields="(*)", $arg=""){
/*
# Retrieve result count
#
# - parameter #1: string $table, table name
# - parameter #2: string $fields, count fields, default (*)
# - parameter #3: string $arg, count string, default null
# - return result array, or error if (error reporting = on, error occured, boolean)
# - scope public
*/
if($this->mySQLresult = @mysql_query("SELECT COUNT".$fields." FROM ".$table." ".$arg)){
$rows = $this->mySQLrows = @mysql_fetch_array($this->mySQLresult);
return $rows[0];
}else{
$this->dbError("dbCount ($query)");
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Close(){
/*
# Close mySQL server connection
#
# - parameters none
# - return null
# - scope public
*/
mysql_close();
$this->dbError("dbClose");
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Delete($table, $arg){
/*
# Delete with args
#
# - parameter #1: string $table, table name
# - parameter #2: string $arg, delete string
# - return result array, or error if (error reporting = on, error occured, boolean)
# - scope public
*/
// echo "DELETE FROM ".MUSER.$table." WHERE ".$arg; // debug
if($arg == ""){
if($result = $this->mySQLresult = @mysql_query("DELETE FROM ".$table)){
return $result;
}else{
$this->dbError("db_Delete ($query)");
return FALSE;
}
}else{
if($result = $this->mySQLresult = @mysql_query("DELETE FROM ".$table." WHERE ".$arg)){
return $result;
}else{
$this->dbError("db_Delete ($query)");
return FALSE;
}
}
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function db_Rows(){
/*
# Return affected rows
#
# - parameters none
# - return affected rows, or error if (error reporting = on, error occured, boolean)
# - scope public
*/
$rows = $this->mySQLrows = @mysql_num_rows($this->mySQLresult);
return $rows;
$this->dbError("db_Rows");
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
function dbError($from){
/*
# Return affected rows
#
# - parameter #1 string $from, routine that called this function
# - return error message on mySQL error
# - scope private
*/
if($error_message = @mysql_error()){
if($this->mySQLerror == TRUE){
echo "<b>mySQL Error!</b> Function: $from. [".@mysql_errno()." - $error_message]<br />";
return $error_message;
}
}
}
}
?>