Link to home
Start Free TrialLog in
Avatar of doctorbill
doctorbillFlag 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
Avatar of ste5an
ste5an
Flag of Germany image

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.
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
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.
Avatar of doctorbill

ASKER

Can you explain exactly how to use phpcs and pcpcbf please
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.
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.
Thing is I am using windows
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
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 ??
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

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
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
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Will give it a go
Perfect -yet again a big Thanks to you Chris
Thanks all
You're welcome!

Good luck!