Joomla website breaks when include custom code file - Joomla! Forum - community, help and support


i've posted problem have ( viewtopic.php?f=625&t=785338 ) website. , noticed problem happens when insert code have , need on site. in code have class , use around files.

things worked 2 months , don't work. haven't change on code , have used in previous templates in past.

i guess i'm not including correctly way joomla likes but, can't understand what's going on.

here's class simple db connection , link id:

code: select all

// class db: connects database , 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 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 mysql server";
    }// end connect function
/////////////////////////////////////////   
  function __talktodb__(){
     
      $this->result = mysql_query( $this->query, $this->linkid );
     
      if( !$this->result ){
        echo ( "query: '" . $this->query . "', failed 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

?>


here's file include:

code: select all

<?php
// select random activity
$num_acts_display = 2;

$query = "select id activity 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 * activity 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>



here's how include it:

code: select all

 include( "templates/" . $this->template . "/includes/db.class" );

include( "templates/" . $this->template . "/random-figureo.php" );



what doing wrong? i'm using j!2.5.8 php version: 2.5.3

thanks in advanced time , help.

i found out problem:

this extension deprecated of php 5.5.0, , removed in future. instead, mysqli or pdo_mysql extension should used.


so, changed files' mysql extension mysqli , works...

i'm still using php 5.3 , looks doesn't mysql_fetch_array...

thanks time. hope helps else in future. took me 3 days of frustration, time, , site being offline.





Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support