Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

OOP issues migrating to php5

Posted on 2007-10-11
8
Medium Priority
?
168 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:bobo1979a
  • 4
  • 2
6 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 20057768
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
 

Author Comment

by:bobo1979a
ID: 20058208
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
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 20058322
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:bobo1979a
ID: 20058719
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
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 1000 total points
ID: 20060595

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
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 20060613
An additional thought, if you are using php mysqli commands, ensure that php.ini has a section

[Extensions]
extension = mysqli.so
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, we’ll look at how to deploy ProxySQL.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question