PHP Mysql issue with old website

Hello,

I have copied a fully working php based auction website from an old web server running PHP 5 to a new hosting server running PHP 5.5.  The new ISP insists on using the latest PHP version so this is not something I have control over.  As a result when I try and run the php program / website i get db connection errors.  Can anyone help me as I have no PHP experience and whilst ive tried a few things I cannot get the site working?

If i browse any PHP page of the website I get a page as follows:

PHP error happened

Technical information
Error type      8192
Error description      mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead
URL      www.xyz.net/output-orig/lot_details_list.php?
Error file      /home/xyz/public_html/output-orig/include/dbconnection.php
Error line      9
SQL query      

Therefore I downloaded the MySQL to MySQLI converter and ran this on the directory.  Now I get another error for every page:

PHP error happened

Technical information
Error type      2
Error description      mysqli_query() expects parameter 1 to be mysqli, null given
URL      www.xyz.net/output/lot_details_list.php?
Error file      /home/xyz/public_html/output/include/dbconnection.php
Error line      22
SQL query      SELECT lot_id, lot_name, start_date, start_time, location_ref, comments, lot_status, website FROM lot_details

The database connection file - Original:
dbconnection-Original.php


The database connection file - Converted
dbconnection-Converted.php:


Sample file - Original:
lot-details-list-Original.php


Sample file - Converted:
lot-details-list-Converted.php



Is anyone able to help me get the site working?

Thanks
LVL 1
cloughsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Your db queries need a reference to a valid connection, but your db_connect is not returning the reference to the connection.  In "dbconnection-Converted.php", you need to add "return $conn;" to the end of the db_connect() function -- see below:
function db_connect() 
{
    global $host,$user,$pwd,$errstr,$sys_dbname,$port;
	$strhost=$host;
	if($port && $port!=3306)
		$strhost=$strhost.":".$port;
	$conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect($strhost, $user, $pwd));
	
return $conn; // add this line to your file
}

Open in new window

0
cloughsAuthor Commented:
Hello,
Thanks for your help with this.  If I add that as you recommend all pages give this error now:

Error type      256
Error description      No database selected
URL      www.xyz.net/output/lot_details_list.php?
Error file      /home/xyz/public_html/output/include/dbconnection.php
Error line      24
SQL query      SELECT lot_id, lot_name, start_date, start_time, location_ref, comments, lot_status, website FROM lot_details
0
Ray PaseurCommented:
Here's a full explanation of what's going on and why.  We've known about this for more than five years, but some people still get caught by the changes.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

If you go back to the original MySQL code you may be able to suppress the messages by reducing the error reporting levels.  However this is like putting a piece of black electrical tape over the warning light.  It fixes a symptom, but leaves the problem for another date.  

I think you would be better off refactoring this application, at least with respect to the data base portion.  Automated code converters are notoriously inaccurate, especially when dealing with poorly designed code sets, and the original PHP code looks like something from PHP4.  There are a lot of trip-wires lurking in those functions, and as written, they are completely untestable.  A better solution would be to have a professional programmer make the conversion to the object-oriented MySQLi or PDO extensions.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

cloughsAuthor Commented:
Hi Ray,
Thanks for the feedback.  
I can see the reasons why PHP are changing things from the links you posted and it makes sense.  

I have tried reducing logging levels but this doesn't seem to work as a temporary work around.  If we can at least get it working as it is now, it would buy time for the code to be upgraded over time by a PHP guru.  However as it stands now the clients business revolves around this site and they cant use it so need a quick solution.  I have a full backup of the original code and the "converted code" so thats no problem.  I just assumed that since all pages point to this dbconnection.php file as being the main issue that if we can fix this, that the site will start working again.

Thanks
0
Ray PaseurCommented:
"Reducing logging levels" is not the same as suppressing the warning / deprecated messages.  The risk, of course, is that you may suppress messages you need to see (from other sources, not MySQL).  This is what I might try first.

Add the following statement to the top of your initial PHP script, probably the one about the db connection.
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);

Open in new window

I can't guarantee that this will work, because it looks like there are other parts to the application (perhaps it was built on some kind of primitive framework), and the other parts may interfere with our efforts to get PHP 5.5 to be "forgiving."  But it's worth a try.
0
cloughsAuthor Commented:
Hi Ray,

Thanks for the help, this doesnt appear to have worked.  Like you say this code might be based on some old framework.

Thanks
0
Ray PaseurCommented:
What happened, exactly?  It's not easy to guess from where I sit, but if I know the symptoms there might be other things to try.
0
hieloCommented:
I don't see where you are setting the name of the database (my guess is it is defined in 'include/dbcommon.php'), but assuming that it is in $sys_dbname, then add it to the mysqli_connect() call (see highlighted changes below):

function db_connect()
{
    global $host,$user,$pwd,$errstr,$sys_dbname,$port;
      $strhost=$host;
      if($port && $port!=3306)
            $strhost=$strhost.":".$port;
      $conn = ($GLOBALS["___mysqli_ston"] = mysqli_connect( $strhost, $user, $pwd, $sys_dbname ) );
      
return $conn;
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cloughsAuthor Commented:
Using help from both experts i managed to hide the errors on all pages - many thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

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.