OOP issues migrating to php5

Hi, my provider upgraded server's OS (FreeBSD from 5.4 to 6.2), mySQL (5.0.x) and PHP (from 4 to 5.2.x).
Now my application don't work anymore and I'm becoming crazy finding why.

I have a page, that loads data from the DB using classes:
<?
require_once("../settings/impostazioni.php");
require_once("../libs/db_obj_class.php");

$table_name = "banner";
$db = new db_obj($table_name);
$db->search();
$db->assign_first_record();
echo "banner1=".UPLOAD_DIR."/banner/".$db->banner1."&banner2=".UPLOAD_DIR."/banner/".$db->banner2;
?>

Impostazioni.php contains the DB informations and db_obj_class.php contains the Classes and Functions.

When I build the reference of the class
     $db = new db_obj($table_name);
it should pass the table name to the function

public function db_obj($table_name,$db_connection=NULL)
{
    $this->_exists=false;
    $this->_records=array();
    $this->_table_name=$table_name;
   
     if ($db_connection)
         $this->_db_connection=$db_connection;
     else
         $this->db_connect();
         $this->table_list_fields();
}

But that value isn't passed and when I call the Search function
     $db->search();

function search($where=null,$order=null)
{
     $query = "select * from ".$this->_table_name;
     if ($where)
         $query.=" where ".$where;
     if ($order)
         $query.=" order by ".$order;
     if ( ! $res = $this->query($query) )
         return false;

     $n_res = mysql_num_rows( $res );
     for ( $i=0; $i < $n_res; $i++ )
          {
          $this->_records[$i] = new db_obj( $this->_table_name, $this->_db_connection );
          $this->_records[$i]->_exists = true;
          $this->_records[$i]->fetch( mysql_fetch_row( $res ) );
          }
}

function query( $query )
{
     echo $query."<BR>";
     $res = mysql_query( $query, $this->_db_connection );
                  
     $this->debug_notice( $query );
     $this->debug_error( mysql_error() );
                  
     if ( mysql_num_rows($res) ) {
         return $res;
     } else {
         return false;
     }
}

I notice that the table name is empty in the $query (select * from) and it gives me the error:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /usr/local/psa/home/vhosts/naba.it/httpdocs/sito_2006/libs/db_obj_class.php on line 53 (that's the row $res = mysql_query($query, $this->_db_connection); )

The error is the same even if I write the table name directly in the query ($query = "select * from banner";

I just can't understand why the table name isn't passed in the class and why the query doesn't work even if I write it directly.

Thanks in advance
Roberto
bobo1979aAsked:
Who is Participating?
 
Beverley PortlockCommented:

I suspect that this is the cause

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /usr/local/psa/home/vhosts/naba.it/httpdocs/sito_2006/libs/db_obj_class.php on line 54

The phrase "supplied argument is not a valid MySQL-Link resource " means that there has been a query failure or a connection failure. Did you migrate your data from MySQL 4 to MySQL 5? If so, have you set a username and password for the database connection? Under MySQL 4.0 passwords were 16 in length. Under MySQL 4.1+ they became 41 in length.

Reset the passwords of whatever user id you use to connect to the database.
0
 
Beverley PortlockCommented:
After this

$table_name = "banner";
$db = new db_obj($table_name);

put this

echo "<pre>"; print_r($db); echo "</pre>";

What is in $db?

Do the same thing just before your query is run.
0
 
bobo1979aAuthor Commented:
After this

$table_name = "banner";
$db = new db_obj($table_name);

Outputs:

db_obj Object
(
)

then:

echo $query."<BR>";
echo "<pre>"; print_r($db); echo "</pre>";
$res = mysql_query( $query, $this->_db_connection );

Outputs nothing.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Beverley PortlockCommented:
Sounds like the object is not being created. As the very, very, very first line of your code after the first <?php add

error_reporting(E_ALL);

Do any error messages show up? If not can you look in the apache error log usually held at

/var/log/httpd/error_log   or /var/log/apache2/error_log

depending on version. Look at the last entries, use tail -n 20 /var/log/apache2/error_log (or the other one).
0
 
bobo1979aAuthor Commented:
This is the output:

Notice: Undefined property: db_obj::$_table_name in /usr/local/psa/home/vhosts/naba.it/httpdocs/sito_2006/libs/db_obj_class.php on line 68

Notice: Undefined property: db_obj::$_db_connection in /usr/local/psa/home/vhosts/naba.it/httpdocs/sito_2006/libs/db_obj_class.php on line 54

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /usr/local/psa/home/vhosts/naba.it/httpdocs/sito_2006/libs/db_obj_class.php on line 54

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/naba.it/httpdocs/sito_2006/libs/db_obj_class.php on line 59

Notice: Use of undefined constant UPLOAD_DIR - assumed 'UPLOAD_DIR' in /usr/local/psa/home/vhosts/naba.it/httpdocs/sito_2006/sito/_carica_banner.php on line 12

and so on errors...

I understand that the object if is created it's empty. I can't understand why, and why I can't read the constants from inside the class.
0
 
Beverley PortlockCommented:
An additional thought, if you are using php mysqli commands, ensure that php.ini has a section

[Extensions]
extension = mysqli.so
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.