ciao grazie infinite per avermi risposto , ti voglio fare vedere le due classi magari riusciamo a modificare la classe ... posto la mia ::::
Codice PHP:
class DB{
var $dbcore;
var $host ='localhost';
var $user ='root';
var $pass;
var $name;
//PHP5 Constructor
function __construct() {
global $db_host,$db_user,$db_pass,$db_name;
$this->host = $db_host;
$this->user = $db_user;
$this->pass = $db_pass;
$this->name = $db_name;
}
//PHP4 Constructor
function database() {
global $db_host,$db_user,$db_pass,$db_name;
$this->host = $db_host;
$this->user = $db_user;
$this->pass = $db_pass;
$this->name = $db_name;
}
function connect()
{
$this->dbcore = @mysql_connect($this->host,$this->user,$this->pass)or die("non riesco a connettermi".mysql_error());
@mysql_select_db($this->name,$this->dbcore)or die("non riesco selezionare il database");
}
function disconnect()
{
@mysql_close($this->dbcore);
}
function ping() {
if (!mysql_ping($this->dbcore)) {
$this->disconnect();
$this->connect();
}
}
function query($sql) {
$result = mysql_query($sql,$this->dbcore);
if( ! $result )
{
return false;
}
return $result;
}
function getrow($sql) {
$result = $this->query($sql);
$returned = mysql_fetch_assoc($result);
@mysql_free_result($result);
return $returned;
}
function getlist($sql) {
$returned = array();
$result = $this->query($sql);
while ($row = mysql_fetch_assoc($result)) {
$returned[] = $row;
}
@mysql_free_result($result);
return $returned;
}
function getnumrows($sql) {
$result = $this->query($sql);
$num = mysql_num_rows($result);
@mysql_free_result($result);
return $num;
}
}
questa e la classe originale :
Codice PHP:
class flor_db_process{
var $query = "";
var $isFetchMode = false;
var $isUpdateMode = false;
var $isInsertMode = false;
var $resultSet = null;
var $affRows=0;
var $numRows=0;
var $fieldCount = 0;
var $errStr = "";
var $hasErr = false;
var $con = null;
var $isDBConnected = false;
function DBprocess2()
{
$this->openCon();
}
function openCon()
{
$this->closeCon();
global $db;
$dbname ="";
$db_Domain;
$dbname = $cmtDB;
//connecting with mysqli
//
$this->con = mysqli_init();
/* set connection options */
$this->con->options(MYSQLI_INIT_COMMAND, "SET AUTOCOMMIT=0");
$this->con->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
/* connect to server */
error_reporting(0);
if (!defined("DB_DOMAIN") || !defined("DB_USER") || !defined("DB_PASS") || !defined("DB_NAME"))
exit("include common.php?.. db connect info missing for DBProcess2");
$this->con->real_connect(DB_DOMAIN,DB_USER,DB_PASS,DB_NAME,DB_PORT);
error_reporting(E_ALL ^ E_NOTICE);
if (mysqli_connect_errno())
{
$this->hasErr = true;
$this->errStr = "Connect failed: \n" . mysqli_connect_error();
exit($this->errStr);
}
else
{
$this->hasErr=false;
$this->isDBConnected=true;
}
}
//function to close db connection
function closeCon()
{
//disconnecting with mysqli
//
if ($this->isDBConnected)
$this->con->close();
$this->con=null;
}
function processQuery()
{
global $errReportingType;
if (!$this->query)
return null;
if (!$this->con)
$this->openCon();
error_reporting(0);
$tmpResult = $this->con->query($this->query);
error_reporting($errReportingType);
if ($this->con->error=="")
{
$this->hasErr = false;
if ($this->isFetchMode)
{
$this->resultSet = $tmpResult;
if ($tmpResult)
{
$this->numRows = $tmpResult->num_rows;
$this->fieldCount = $this->field_count;
}
else
$this->numRows = 0;
}
elseif($this->isUpdateMode)
{
$this->affRows = $this->con->affected_rows;
}
elseif($this->isInsertMode)
{
$this->affRows = $this->con->affected_rows;
return $this->con->insert_id;
}
}
else
{
$this->hasErr = true;
$this->errStr = $this->con->error;
if (APPMODE!="live")
$this->errStr = $this->query."___".$this->errStr;
if ($this->isInsertMode)
return null;
}
}
function fetchQuery($qry)
{
$this->query = $qry;
$this->isFetchMode = true;
$this->isUpdateMode = false;
$this->isInsertMode =false;
$this->processQuery();
}
function insertQuery($qry)
{
$this->query = $qry;
$this->isFetchMode = false;
$this->isUpdateMode = false;
$this->isInsertMode = true;
$insert_id = $this->processQuery();
return $insert_id;
}
function updateQuery($qry)
{
$this->query = $qry;
$this->isFetchMode = false;
$this->isUpdateMode = true;
$this->isInsertMode = false;
$this->processQuery();
}
function getRow()
{
$row = $this->resultSet->fetch_row();
if (isset($row))
return $row;
else
return null;
}
function getRow2()
{
$row = $this->resultSet->fetch_assoc();
if (isset($row))
return $row;
else
return null;
}
function reset()
{
mysqli_data_seek($this->resultSet,0);
}
}