Avatar of doctorbill
doctorbill
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Deprecated PHP Connection

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_TickTockDB = "localhost";
$database_TickTockDB = "inventas";
$username_TickTockDB = "xxxx";
$password_TickTockDB = "xxxxxxxxxxx";
$TickTockDB = mysql_pconnect($hostname_TickTockDB, $username_TickTockDB, $password_TickTockDB) or trigger_error(mysql_error(),E_USER_ERROR);
?>

It looks as if I have a deprecated connection string
Can someone please suggest an alternative for this connection
PHPApache Web Server

Avatar of undefined
Last Comment
David Favor

8/22/2022 - Mon
ste5an

What do you mean by "deprecated connection string"? The only deprecated thing is that your using a deprecated method, of a pretty ancient API.

See PHP offers three different APIs to connect to MySQL..

But this means rewriting your application.
lenamtl

Hi,

I'm using this backend script which use PDO and it is very well coded and secure, so this can help you to start to update your application.
https://codecanyon.net/item/advanced-security-php-registerlogin-system/5282621

So I would recommend to use PDO with prepared statement for security reason
https://www.php.net/manual/en/ref.pdo-mysql.php
https://www.w3schools.com/php/php_mysql_connect.asp
https://www.w3schools.com/php/php_mysql_prepared_statements.asp

And update your application to PHP7+ for security reason too, also PHP 7.3 have more security for cookies.
https://www.php.net/manual/en/migration70.php

You can use a script to check PHP compatibility
https://github.com/PHPCompatibility/PHPCompatibility
David Favor

mysql_pconnect() - Super old, as this was deprecated in PHP-5.6 + completely removed/retired in PHP-7.0 (as I recall).

Tip: If you're using mysql_pconnect() this likely means you have many other old pre-PHP-5.6 artifacts which will fail (raise Fatal exceptions on any of the PHP-7.X versions) in PHP-7.4.1 (latest stable), so best if you scan your entire code base with phpcs, then potentially use phpcbf to fix many problems mechanically (rather than via hand edits).

https://www.experts-exchange.com/questions/29150594/Updating-website-page-to-PHP-7.html covers details of installing phpcs/phpcbf, verifying they're working, then running these tools on large file sets.

Just a few days I ran a search across, many 1000s of files, which only took a couple of minutes to run.

phpcs/phpcbf - One of the unsung heroes of Net Tech.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
doctorbill

ASKER
Can you explain exactly how to use phpcs and pcpcbf please
David Favor

Refer to the URL above.

Example syntax, extracted from URL above...

time nice -19 phpcs -d xdebug.show_exception_trace=0 -p --parallel=16 --standard=PHPCompatibility \
               --encoding=utf-8 --extensions=php,inc,lib,js,css,html --runtime-set testVersion 7.3 /cluster/sites \
               > ~/app-php-5.6-tofix.txt 2>/dev/null

Open in new window


And you still must use instructions from URL above to install phpcs/phpcbf.

Me personally, I just install this on every project (LXD container) now as part of the setup sequence for any new project.

This tool is so helpful + takes up such little disk space, it's worth having around all the time.
lenamtl

Hi,

See this answer it explain very well how to install and use PHP compatibility
https://www.experts-exchange.com/questions/29152482/How-to-set-and-use-PHPCodeSniffer-with-PHPCompatibility.html?anchorAnswerId=42912921#a42912921
let me know if you need more info, it is a lot easier to run it on Linux.

Note it won't work if you scan for 7 or 7.1.3 PHP version
but it will work with 7.0, 7.1, 7.2
for more info https://github.com/PHPCompatibility/PHPCompatibility/issues/858
for example you can scan for everything between 2 versions like 5.6-7.2

Some error won't be detected like header already sent so you will need to enable error display and also test manually.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
doctorbill

ASKER
Thing is I am using windows
lenamtl

Hi,

to install on Windows you will need to use Composer and add phpcs + phpcbf to your $PATH variable.
There are some instructions to install Composer on Windows here to try
https://phptherightway.com/

You have some instruction from Github
https://github.com/PHPCompatibility/PHPCompatibility
doctorbill

ASKER
That is done:

I am following this link:
https://www.hostinger.co.uk/tutorials/how-to-install-composer

When I run the following:
require '/vendor/autoload.php'
I get an error - "require is not recognised as an internal or external command, operable program or batch file

If I run the php demo.php file I get the following error:
PHP parse error: syntax error, unexpected 'Timer@ (T_STRING) in c:\phptimer\demo.php on line 3
Parse error: syntax error, unexpected 'Timer' (T_STRNG) in c:\phptimer\demo.php on line 3

Any ideas please ??
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
lenamtl

You have to set environnement variable
https://getcomposer.org/doc/00-intro.md#installation-windows
Chris Stanyon

The require line needs to go at the top of your php script:

<?php
require '/vendor/autoload.php';

...rest of your code goes here...

Open in new window

doctorbill

ASKER
I have tried this:
<?php
require __DIR__ . '/vendor/autoload.php';

Timer::start();
// your code
$time = Timer::stop();
var_dump($time);
print Timer::secondsToTimeString($time);
?>

And this:
<?php
require  '/vendor/autoload.php';

Timer::start();
// your code
$time = Timer::stop();
var_dump($time);
print Timer::secondsToTimeString($time);
?>

In both cases I get this error:
PHP Fatal error:  Uncaught Error: Class 'Timer' not found in C:\phptimer\demo.php:4
Stack trace:
#0 {main}
  thrown in C:\phptimer\demo.php on line 4

Fatal error: Uncaught Error: Class 'Timer' not found in C:\phptimer\demo.php:4
Stack trace:
#0 {main}
  thrown in C:\phptimer\demo.php on line 4
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Chris Stanyon

Right. That sounds like you haven't got the Timer library loaded. In the root of your app, you should have a composer.json file. You should also have a vendor folder. Check in the composer.json file to make sure your require block includes the Timer library. Then check in your vendor folder to see if the files are there. You should have a folder called phpunit and under that a folder called php-timer.

If you don't have those files and folders, then you haven't installed your dependencies correctly.

Also make sure that the script you're trying to run is in the root of your folder - at the same level as the vendor folder
ASKER CERTIFIED SOLUTION
Chris Stanyon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
doctorbill

ASKER
Will give it a go
doctorbill

ASKER
Perfect -yet again a big Thanks to you Chris
Your help has saved me hundreds of hours of internet surfing.
fblack61
doctorbill

ASKER
Thanks all
David Favor

You're welcome!

Good luck!