jagguy
asked on
connect mysql
Hi,
I am using php 5.4 on my host server. The correct way to connect to a mysql db in a php file is what syntax these days on php 5.4.
I ask this because I did the 'old' way and i cant find the newer way someone told me a while ago.
I am using php 5.4 on my host server. The correct way to connect to a mysql db in a php file is what syntax these days on php 5.4.
I ask this because I did the 'old' way and i cant find the newer way someone told me a while ago.
The easiest conversion from obsolete MySQL functions is the object-oriented MySQLi extension. I say "easiest" because of these factors:
1. There can be two simultaneous connections to the DB engine. You do not have to convert all of the old MySQL code at once - you can convert it query-by-query.
2. There are no changes needed to the query strings (in PDO almost every query string will have to change).
3. There is almost 100% 1:1 matching of functionality (in PDO some of the MySQL operations are lost, eg, data_seek() does not exist).
4. There are relatively few code changes needed. If you were to choose procedural MySQLi instead of OOP MySQLi, every call to the query() function would have to change because the procedural version requires the database link identifier as the first argument.
5. Anybody who really believes that using PDO will somehow magically let you change out the underlying data base engine, without creating havoc in your application software, has never tried to change out an underlying data base engine.
So with that as my reasons to support the choice of object-oriented MySQLi, here is the article that shows how to make the switch to a modern data base extension.
https://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're familiar with MySQL and have code that uses the MySQL extension, this web page will map the familiar-but-obsolete MySQL functions to MySQLi.
http://iconoun.com/mysql_mysqli_pdo_function_map.php
I've been through a few of these conversions in my own applications and in consulting assignments. It has always gone smoothly. Best of luck with your project, ~Ray
1. There can be two simultaneous connections to the DB engine. You do not have to convert all of the old MySQL code at once - you can convert it query-by-query.
2. There are no changes needed to the query strings (in PDO almost every query string will have to change).
3. There is almost 100% 1:1 matching of functionality (in PDO some of the MySQL operations are lost, eg, data_seek() does not exist).
4. There are relatively few code changes needed. If you were to choose procedural MySQLi instead of OOP MySQLi, every call to the query() function would have to change because the procedural version requires the database link identifier as the first argument.
5. Anybody who really believes that using PDO will somehow magically let you change out the underlying data base engine, without creating havoc in your application software, has never tried to change out an underlying data base engine.
So with that as my reasons to support the choice of object-oriented MySQLi, here is the article that shows how to make the switch to a modern data base extension.
https://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're familiar with MySQL and have code that uses the MySQL extension, this web page will map the familiar-but-obsolete MySQL functions to MySQLi.
http://iconoun.com/mysql_mysqli_pdo_function_map.php
I've been through a few of these conversions in my own applications and in consulting assignments. It has always gone smoothly. Best of luck with your project, ~Ray
ASKER
ok I will take your advice and have a look
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
- mysqli, which gives you an option of working in procedural way, somewhat similar to the old mysql extension
- PDO, which is purely OO and can, in theory, allow you to work with any database.
I'll let Ray give you a link to his tutorials on using either mysqli or PDO (or just go to his profile and look at all his articles: https://www.experts-exchange.com/members/Ray_Paseur.html).
HTH,
Dan