2013-01-12 34 views
0

我发布了一个问题我有(http://stackoverflow.com/questions/14263141/joomla-website-not-working-after-moving-to-new-server)与我的网站。并注意到只有当我在网站上插入一些我需要的代码时才会出现问题。在代码中我有一个类并在我的文件中使用它。当包含自定义代码文件时Joomla网站中断

事情工作约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 

?> 

这里的另一个文件I包括:

<?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&amp;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&amp;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

+0

当它不起作用时,您收到的错误消息是什么? –

+0

既然你说你搬到了新的服务器,我会仔细检查一下,以确保你的MySQL主机名'$ this-> sqlhost =“localhost”;'确实是'localhost'。我记得我的网站中断,因为主机名已从本地主机更改为域名,例如db.myhost.com。 –

+0

如果我删除包含,事情完美。 如果包含,那么joomla的模块不会加载,除了我包含的代码外,大部分页面都是空白的。 – Wilson

回答

0

我只是发现了问题:

块引用此扩展不赞成PHP 5.5.0的,并会在将来被移除。相反,应该使用MySQLi或PDO_MySQL扩展。

于是,我改变了我的文件mysql扩展到mysqli的,现在一切正常......

我仍然在使用PHP 5.3,看起来像它不喜欢的mysql_fetch_array ...

谢谢你们所有的时间。希望这有助于未来的其他人。这花了我三天的时间,我的网站处于离线状态。

相关问题