我在我的网站上发布了一个问题(http://stackoverflow.com/questions/14263141/joomla-website-not-working-after-moving-to-new-server)。并注意到问题只有在我在网站上插入一些我拥有和需要的代码时才会发生。在代码中我有一个类并在我的文件周围使用它。
事情工作了大约 2 个月,现在不起作用。我没有更改代码上的任何内容,并且过去曾在以前的模板中使用过它。
我想我没有按照 Joomla 喜欢的方式正确地包含它,但是,无法理解发生了什么。
这是一个简单的数据库连接和链接 ID 的类:
// Class db: Connects to database and returns linkid.
class MY_DB{
var $sqlhost;
var $sqluser;
var $sqlpass;
var $sqldb;
var $err;
var $status;
var $num_rows;
var $result;
var $linkid;
var $query;
var $rows = Array();
var $last_insert_id;
function MY_DB( $query="", $db="" ){
if( $db != "" ){ $this->sqldb = $db; }
else{ $this->sqldb = "dbase"; }
$this->sqlhost = "localhost";
$this->sqluser = "root";
$this->sqlpass = "pass";
$this->query = $query;
if( $this->query == "" ){
$this->__Connect__();
}
else{
$this->__Connect__();
$this->__TalkToDB__();
}
}// end constructor Session
/////////////////////////////////////////
function __Connect__(){
//connect to mysql
$this->linkid = mysql_connect( $this->sqlhost, $this->sqluser, $this->sqlpass );
if( $this->linkid ){
$this->result = mysql_select_db( $this->sqldb, $this->linkid );
}
else
$this->err = "Could not connect to MySQL server";
}// end Connect function
/////////////////////////////////////////
function __TalkToDb__(){
$this->result = mysql_query( $this->query, $this->linkid );
if( !$this->result ){
echo ( "Query: '" . $this->query . "', failed with error message: -- " . mysql_error() . " --" );
}
}// end TalkToDb function
//////////////////////////////////////////
function __CountRows__(){
$this->num_rows = mysql_num_rows( $this->result );
return $this->num_rows;
}
//////////////////////////////////////////
function __LastInsertedId__()
{
return mysql_insert_id( $this->linkid );
}
}// end class definition
?>
这是我包含的另一个文件:
<?php
// select random activity
$num_acts_display = 2;
$query = "select id from activity where enabled='Y'";
$all_ids = array();
$act_id = new MY_DB( $query );
while( $all = mysql_fetch_array($act_id->result,MYSQL_BOTH) ){
$all_ids[] = $all['id'];
}
// shuffle it
shuffle( $all_ids );
// re-shuffle it
shuffle( $all_ids );
?>
<div class="random-figureo">
<ul>
<?
for( $i = 0; $i < $num_acts_display; $i++ ){
$query = "select * from activity where id=".$all_ids[$i];
$act = new MY_DB( $query );
$a = mysql_fetch_array($act->result,MYSQL_BOTH)
?>
<li>
<div class="random_img">
<a href="<?=$this->baseurl?>/index.php?option=com_content&view=article&id=537&Itemid=194&page=thumbnails&act_id=<?=$a['id']?>">
<?
$portada = get_portada($a['id'], "", true);
if( $portada == "none" ){
?>
<div style="background:#666; width:100px; height:65px; padding:0px; margin:0px;"></div>
<?}
else{// "templates/" . $this->template .
?>
<img src="<?= "templates/" . $this->template . substr( $a['directory'],1,strlen($a['directory']) ) . "/" . $portada ?>" width="100" height="65" alt="<?=$a['act_name']?>" />
<?}?>
</a>
</div>
<br />
<div class="random_title">
<a href="<?=$this->baseurl?>/index.php?option=com_content&view=article&id=537&Itemid=194&page=thumbnails&act_id=<?=$a['id']?>"><?=$a['act_name']?></a>
</div>
</li>
<?
}
?>
</ul>
</div>
以下是我包含它的方式:
include( "templates/" . $this->template . "/includes/db.class" );
include( "templates/" . $this->template . "/random-figureo.php" );
我究竟做错了什么?我正在使用 J!2.5.8 和 PHP 版本:5.3