PHP code to connect to MySQL not working after moving to a new server

We have a old custom built content management system which refers to a file with the below code to login. Once we migrated the website to a new server, it will not let us login. I believe it is because mysql_pconnect is deprecated since we are using PHP 5.5 (not sure what it was before though).

[embed=425,349]<?php

FileName=“Connection_php_mysql.htm”

Type=“MYSQL”

HTTP=“true”

$hostname_login = “localhost”;
$database_login = “XXXXXXXX”;
$username_login = “XXXXXXXX”;
$password_login = “XXXXXXXX”;
$login = mysql_pconnect($hostname_login, $username_login, $password_login) or die(mysql_error());
?>[/embed]

Does anyone know why we can’t login? How could I update this code if the error is because it is deprecated?

Thanks

First, check with your host to verify the connection details of their server. They can be different, some use localhost others don’t.

Your code is probably going to need a major overhaul. We have a few freelancers here that could get your code up to current and protected standards.

Thank you for the reply. I already tried changing localhost to the IP address. Are you confident that the code is too outdated for me to login or could there be another issue?

We are developing a new site with Wordpress and am just looking for a quick fix temporarily. Any suggestions to change this?

1 are you sure the database was moved to the new server?
2 did you check with the host for their connection string?

Does your server really need a persistent connection? Some servers do not allow this without PHP.INI
changes. Try it without the “mysql_pconnect”… Test it with just a standard connection. “mysql_connect”.

And, as Astonecipher normally suggests, you might want to update to MYSQLi instead of MYSQL…

From the PHP.NET site they say this about the "pconnect’… Note that when the script is over or completed,
that it does not close the connection. This could cause a ton of security issues for hackers to access the
connection after your scripts run… Not sure if this is needed or if it is safe!

mysql_pconnect() acts very much like mysql_connect() with two major differences.

First, when connecting, the function would first try to find a (persistent) link that’s already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection.

Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()).

This type of link is therefore called ‘persistent’.

Thanks everyone. Do you know what php.ini setting I would have to change for it to work?

This will be temporary since we are creating a new CMS but it would be great to get this working soon.

If you are just trying to run your old site temporarily as a backup until you get the new one in place I would do the following:

[ol][li]Identify the PHP you were running, download (and compile if on Linux change the default prefix)[/li]
[li]Configure the old site to work with the old PHP version in the meantime, run in cgi mode[/li][/ol]

Different PHP versions can run happily together on the same web server as cgi scripts. I have resorted to this solution on some of my legacy sites (which I have no intention of changing code because they work). If the customers eventually want to upgrade their code then I can do it and switch them over to the newer versions.

Sponsor our Newsletter | Privacy Policy | Terms of Service