Solved

connect mysql

Posted on 2014-04-27
4
446 Views
Last Modified: 2014-05-03
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.
0
Comment
Question by:jagguy
4 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 40026565
The new and accepted way of working with MySQL from PHP is a tie:
- 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: http://www.experts-exchange.com/members/Ray_Paseur.html).

HTH,
Dan
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40027110
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.
http://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
0
 

Author Comment

by:jagguy
ID: 40027165
ok I will take your advice and have a look
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 40027837
greetings  jagguy, your path to using MYSQL engine on PHP ver 5.4 may depend somewhat on your current understanding of the OLD mysql uses.
I try and only use the php MySQL Improved Extension (mysqli) and NOT the PDO, if at all possible. But I would highly recommend going through the new Improved mysqli explanations in the PHP manual, there is a difference in the DB connection from the old way, as you now need to include the name of the database. Manual for it is here-
    http://www.php.net/manual/en/mysqli.construct.php

There is a whole section in the manual about using this at -
    http://www.php.net/manual/en/book.mysqli.php

you should go through all the examples in the "Quick start guide" which starts with the "Dual procedural and object-oriented interface" at -
    http://www.php.net/manual/en/mysqli.quickstart.dual-interface.php

If you are NOT familiar with the PHP Object Oriented code writes, you should try and use the procedural style of mysqli code, which I feel really resembles the OLD MYSQL code writes, except for some certain changes.

This quick start guide really helped me when I got into the Improved version, and the PHP manual can show you the way to use all of the different Improved functions-methods.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question