cancel
Showing results for 
Search instead for 
Did you mean: 

PHP MySql Unable to connect Are there recent changes

DavidEvans1
Newbie
Posts: 2
Thanks: 2
Registered: ‎19-08-2018

PHP MySql Unable to connect Are there recent changes

Until very recently I have had a page that serves up a database on ccgi.username.plus.com.

Today, the PHP seems to be working, but the page that completes the connection does not complete, or issue an error message.

The php line I use is:

$connection = mysql_connect($host,$user,$password) or die ("couldn't connect to new server");

I have verified that the $host, $user and $password have been set correctly using the MySql Manager at hosting.plus.com

 

I saw another thread that there has been an upgrade to PHP7.

 

Do I need to change some basic PHP functions?

Before you ask, I have verified that the data is visible in the Database manager on hosting.plus.com

9 REPLIES 9
MauriceC
Superuser
Superuser
Posts: 4,071
Thanks: 2,492
Fixes: 17
Registered: ‎10-04-2007

Re: PHP MySql Unable to connect Are there recent changes

This subject came up a few days back.   Suggest you read https://community.plus.net/t5/Everything-else/PHP-files-not-being-served-at-ccgi-username-plus-com/m...  particularly @bobpullen  post #10

 

Hopefully that Topic will give you some clues?

Superusers are not staff, but they do have a direct line of communication into the business in order to raise issues, concerns and feedback from the community.

bobpullen
Community Gaffer
Community Gaffer
Posts: 15,042
Thanks: 2,693
Fixes: 171
Registered: ‎04-04-2007

Re: PHP MySql Unable to connect Are there recent changes

The mysql_ extension has been removed in PHP 7. I suspect you need to use mysqli_connect instead. Failing that, you can drop the PHP version back to 5 using the PHP Manager in the Hosting Control Panel.

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵

spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,370
Fixes: 75
Registered: ‎06-04-2007

Re: PHP MySql Unable to connect Are there recent changes

Yes, as mentioned in the topic @MauriceC linked to the version of PHP was updated a few days ago to version 7.1.15. Whilst continued use of mysql_* functions was deprecated some time ago, the complete extension was removed in PHP 7 and needs to be replaced by mysqli_* equivalents. For example the equivalent of your mysql_connect statement, and the mysql_select_db statement which will follow it is

$connection = @mysqli_connect($host, $user, $password, $database)
  or die('Connect Error ('
. mysqli_connect_errno() . ') ' . mysqli_connect_error());

It is necessary that $connection is the first parameter in subsequent mysqli_* statements which access the database (rather than just manipulating query result objects).

The PHP manual which references all the mysqli functions can be found at http://php.net/manual/en/mysqli.construct.php

Updating from mysql_* to mysqli_* requires care but is not difficult.

David
DavidEvans1
Newbie
Posts: 2
Thanks: 2
Registered: ‎19-08-2018

Re: PHP MySql Unable to connect Are there recent changes

Many thanks to all respondents

I have temporarily reverted to PHP5, and renamed htaccess. file.

I shall be looking to revise to mySqli in the very near future.

David

ianmckinnon
Newbie
Posts: 1
Registered: ‎29-11-2013

Re: PHP MySql Unable to connect Are there recent changes

I am having the same difficulty. Nothing has changed on the client or the server but no data is retrieved.

Using Linux, PHP, MySQL and Javascript to retrieve data into a series of Javascript dropdowns.

Has worked perfectly for years yet Plusnet techies can find no reason why nothiing is being retrieved.

It's as though the Database functionality is of relatively little interest. 

I'd move my Database to another host but that evades the issue of why it's stopped.

spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,370
Fixes: 75
Registered: ‎06-04-2007

Re: PHP MySql Unable to connect Are there recent changes

Almost certainly the problem will be because Hostopis recently updated PHP to version 7.1.15. This version no longer provides the basic MySQL extension which was accessed using mysql_* function calls. All such calls need to be replaced by improved MySQL equivalents which include a letter "i", ie mysqli_*

Guidance on what is required is given in message 4 above which is expanded on in post https://community.plus.net/t5/Everything-else/PHP-files-not-being-served-at-ccgi-username-plus-com/m...

The ereg extension was also removed which includes the split and spliti functions. preg_split is a suitable replacement for those.

It is possible to use phpManager from the Hosting Control Panel to temporarily switch back to PHP 5.6 but doing that could cause problems if PHP sessions are used.

David
SorNet117
Dabbler
Posts: 14
Thanks: 1
Registered: ‎18-09-2017

Re: PHP MySql Unable to connect Are there recent changes

Can anyone pleas help!

 

With the upgrade to PHP7 all may session/mysql related php pages became inaccessible.

After weeks of reading forum posts, I have finally managed to sort out most mysql to mysgli issues.

However I am stuck on one problem which throws a Fatal error, namely: Uncaught Error: Call to undefined function mysqli_result() in /services/webpages/util/c/c/ccgi….. file.php:43 Stack trace: #0 {main} thrown in /services/webpages/util/c/c/ccgi……..file.php on line 43

The php code in question is as follows:

 

Code1.png

bobpullen
Community Gaffer
Community Gaffer
Posts: 15,042
Thanks: 2,693
Fixes: 171
Registered: ‎04-04-2007

Re: PHP MySql Unable to connect Are there recent changes

Doesn't look like there's a mysqli_result() function in PHP7.

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵

spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,370
Fixes: 75
Registered: ‎06-04-2007

Re: PHP MySql Unable to connect Are there recent changes

As Bob said the PHP developers did not replace mysql_result when building the mysqli extension. This was for very good reasons.

To make your code work try

$row = mysqli_fetch_row($result);

to extract the complete row from the query resource (albeit an array with only one element(, then use $row[0] in place of the failing mysqli_result() call on line 43.

David