Peter S skrev:
Det måste finnas annan kod utanför Home() som definierar Conn, QueryRS() m.fl.
Men, den senaste koden du postade hjälpte ändå :)
$sql = "select * from vote_wallpaper where cat_id='7' order by upload_date,upload_time desc limit 4";
$result = $this->Conn->QueryRS($sql);
if (!$result->EOF){
$data = $result->getarray();
$this->Template->assignVal('eight_dim_img',$data);//print_r($data);
}
Det hjälpte tyvärr inte. (Får samma fel.)
dbconnect
class dbConnect
{
var $conn;
// public variables
var $LastErrorMessage = '';
var $LastErrorNumber = 0;
var $Persistent = 0;
var $LastInsertID = 0;
var $LastAffectedRows = 0;
// private variables
var $_Server;
var $_Username;
var $_Password;
var $_Database;
var $_State = 0;
var $_Engine;
function &dbConnect($server = null, $username = null, $password = null, $database = null, $persistent = 0)
{
$this->_Engine = DB_DRIVER;
$this->Persistant = $persistent;
if (($server != null) && ($username != null) && ($database != null))
{
$this->open($server, $username, $password, $database);
}
}
function open($server, $username, $password, $database)
{
$this->_Server = $server;
$this->_Username = $username;
$this->_Password = $password;
$this->_Database = $database;
$this->conn = &ADONewConnection($this->_Engine);
if(DEBUG_MODE)
{
$this->conn->debug = true;
}
if ($this->Persistent == 1)
{
// open a persistent connection
$this->conn->PConnect($this->_Server, $this->_Username, $this->_Password, $this->_Database);
}
else
{
// open a normal connection
$this->conn->Connect($this->_Server, $this->_Username, $this->_Password, $this->_Database);
}
if ($this->conn)
{
$this->_State = 1;
return true;
}
exit(sprintf(CU_ERR_DB_1000));
}
function close()
{
if ($this->_State)
{
$this->conn->close();
$this->_State = 0;
return true;
}
return false;
}
function state()
{
return $this->_State;
}
//This Function is needed to run only SQL commands that does not return anything
//ITS Like insert or update or delete command
function Execute($SQL)
{
$this->QueryPrepare($SQL);
if ($this->_State)
{
if ($this->conn->Execute($SQL)===false)
{
$this->LastErrorMessage = $this->conn->ErrorMsg();
return false;
}
else
{
if(stristr($SQL,"Insert ")!==false) $this->LastInsertID = $this->conn->Insert_ID();
$this->LastAffectedRows = $this->conn->Affected_Rows();
return true;
}
}
return false;
}
//Its Execute a Simple Select Query which returns only 1 field or Value
function ExecuteSingle($strSQL)
{
$this->QueryPrepare($strSQL);
if ($this->_State)
{
$this->conn->SetFetchMode(ADODB_FETCH_NUM);
if ($result = $this->conn->execute($strSQL))
{
return $result->fields[0];
}
else
{
$this->LastErrorMessage = $this->conn->ErrorMsg();
}
$this->conn->SetFetchMode(ADODB_FETCH_ASSOC);
}
return false;
}
//IF query returns only Single row of data then use this.
//If you need indexing from "0" use 0 as second parameter.
//Default is "1" which returns Associative Array
function QuerySingle($strSQL, $associative = 1)
{
switch ($associative)
{
case 0: $this->conn->SetFetchMode(ADODB_FETCH_NUM); break;
case 1: $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); break;
}
$this->QueryPrepare($strSQL);
if ($this->_State)
{
$result = $this->conn->GetRow($strSQL);
if ($result)
{
return $result;
}
else
{
$this->LastErrorMessage = $this->conn->ErrorMsg();
return false;
}
}
return false;
}
function QuerySingleRS($strSQL, $associative = 1)
{
switch ($associative)
{
case 0: $this->conn->SetFetchMode(ADODB_FETCH_NUM); break;
case 1: $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); break;
}
$this->QueryPrepare($strSQL);
if ($this->_State)
{
$result = $this->conn->Execute($strSQL);
if ($result)
{
return $result;
}
else
{
$this->LastErrorMessage = $this->conn->ErrorMsg();
return false;
}
}
return false;
}
function QueryRS($strSQL, $associative = 1)
{
switch ($associative)
{
case 0: $this->conn->SetFetchMode(ADODB_FETCH_NUM); break;
case 1: $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); break;
}
$this->QueryPrepare($strSQL);
if ($this->_State)
{
$result = $this->conn->Execute($strSQL);
if ($result)
{
return $result;
}
else
{
$this->LastErrorMessage = $this->conn->ErrorMsg();
return false;
}
}
return false;
}
//GET ALL THE TUPLES FOR A SELECT
function Query($strSQL, $associative = 1)
{
switch ($associative)
{
case 0: $this->conn->SetFetchMode(ADODB_FETCH_NUM); break;
case 1: $this->conn->SetFetchMode(ADODB_FETCH_ASSOC); break;
}
$this->QueryPrepare($strSQL);
if ($this->_State)
{
$result = $this->conn->GetAll($strSQL);
if ($result)
{
return $result;
}
else
{
$this->LastErrorMessage = $this->conn->ErrorMsg();
return false;
}
}
return false;
}
//Check Wheather Data Exists or Not in Table
//Works Fine For Single Row Check
function dataExists($SQL)
{
$this->QueryPrepare($SQL);
if ($this->_State)
{
$result = $this->QuerySingle($SQL);
if (is_array($result))
{
unset($result);
return true;
}
}
return false;
}
//GET HOW MANY ROWS IN A RECORDSET
function numRows($recordSet)
{
if ($this->_State) {
$result = count($recordSet);
return $result;
}
}
//GET THE RECENT INSERT ID
function getInsertID()
{
return $this->LastInsertID;
}
//GET AFFECTED ROWS
function getAffectedRows()
{
return $this->LastAffectedRows;
}
//TRY TO UPDATE A RECORD, IF NOT FOUND THEN INSERT
function insertOrUpdate($table, $arrFields, $keyCols,$autoQuote=false)
{
$table = str_replace("tbl", ' '.DB_PREFIX, $table);
$ret = $this->conn->Replace($table, $arrFields, $keyCols, $autoQuote);
return $ret;
}
function Prepare($string)
{
if (!get_magic_quotes_gpc())
{
$string = addslashes($string);
}
return trim($string);
}
function QueryPrepare(&$string)
{
$string = str_replace(" tbl", ' '.DB_PREFIX, $string);
$string = str_replace(",tbl", ','.DB_PREFIX, $string);
$string = $this->Prepare($string);
}
}