what is the best way to connect my database to my new website using php and mysql ?

Nadir BELHADJ
Nadir BELHADJ used Ask the Experts™
on
Hi , i'm a computer science  student and i'm working on  a web development project (buiding a website for my higher shcool) . For the moment i had compeleted the front end of the site and i'm dealing with the back end side these days  using mysql and php . my problem is choosing the best way to connect my database to my website , is it mysqli or PDO ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
Commented:
Terminology, you are connecting web site/PHP to the database.

Mysqli in PHP.

Have you already designed the database structure?

The database is the foundation. PHP is the structure.

The means by which the view the client sees is presented/updated depends on what it is you devide for the UI

A general question such as yours is difficult to answer.
It might be a combination of the two.
Nadir BELHADJfull stack web developer

Author

Commented:
so , you mean that the answer of my question depends on the type of the project ( the site ) ?
Distinguished Expert 2017
Commented:
each item has its benefits and drawbacks.
You have to based on your database structure, and business logic/proces who dictate the types of queries you need to extract the data.
Then the means by which you present the data I.e. Using Ajax, json, etc to dynamically update a subset of the display or entire page update when user either requests or the refresh frequency if set to auto refresh....
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Most Valuable Expert 2011
Top Expert 2016
Commented:
Here is an article that shows many of the basics of PHP and MySQLi and PDO working together.  It is written in parallel construction so you can see the similarities and differences in the extensions.  It was originally written because so many obsolete code samples litter the internet and they're full of references to the antiquated MySQL extension, which has been removed from PHP.  Have a look and see if it helps you consolidate your thinking about which way to go.
https://www.experts-exchange.com/articles/11177/PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html

In semi-related news, there are a lot of good examples on the internet, too.  Many of them are identified in this article.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html
Hi,

While both Mysqli and PDO are both provide faster connections to mysql database.  To know which one you should use, I would suggest to browser through the basic difference between them.


Mysqli- means MySQL Improved:
  1. Mysqli is a improved version of mysql functions
  2. It supports Mysql database only
  3. Mysqli supports Procedural and OOPs

PDO - PHP Data Object:
  1. PDO_MYSQL is the driver that helps in connecting php application  to Mysql
  2. http://php.net/manual/en/ref.pdo-mysql.php
  3. http://php.net/manual/en/ref.pdo-mysql.php
  4. PDO supports 12 different drivers(So this helps when there is a need to switch between the databases )
  5. PDO only OOP

Below are couple of links which discuss about the difference between them

https://code.tutsplus.com/tutorials/pdo-vs-mysqli-which-should-you-use--net-24059

http://www.tricksofit.com/2013/11/difference-between-pdo-and-mysqli#.WM1uuBKGOEI
Freelancer
Top Expert 2010
Commented:
Just a thought. If you are already familiar with mysql, mysqli will be easier to use, otherwise I would suggest to learn to use PDO and always use prepared statements.
Prepared statement is the only proper way to run a query
(https://phpdelusions.net/pdo)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial