Best driver for PHP database [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I was just wondering the asnwer to this question..
for a few select, insert, and update querys with only a mysql database which driver is the best? MySQL, MySQLi or PDO for speed?

Don't use the mysql_* functions, that API is depreciated.
MYSQLi is a replacement for MYSQL and also comes with object-oriented and procedural versions.
PDO (PHP Data Objects) is fairly advanced and is a general database abstraction layer with support for MYSQL among other databases.
How to learn PHP, PDO and MYSQLi
Documentation for programming languages
Stack Overflow community
Programming Books
YouTube Channels
Code Course is an excellent resource to learn PHP. Try his website and YouTube Channel.
Good luck! :)
UPDATE: Comparing the Speeds
MYSQLi is slightly faster than PDO and makes programming easy if your familiar with the *mysql_** extension
PDO is not as fast as MYSQLi. However, it offers much easier transition to other databases. It also offers more features (eg. named parameters in prepared statements, object mapping).

The MySQL extension is essentially retired (as of PHP 5.5 or thereabout). Thus, in my opinion, since you are using a MySQL db, you have your choice from the other two (MySQLi supports MySQL only, PDO is MySQL plus a dozen other DB flavors).
Given what you are doing, I don't believe there is going to be significant difference in performance. Some benchmarks indicate that MySQLi is a smidge faster than PDO (depending on what you're doing), so if you really need to squeeze for every millisecond, I'd probably go for MySQLi.

Related

Building an application independent of the SQL engine used [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I wanted to ask that if and how is it possible to make a PHP-based application independent of the SQL engine used?
(Under that I mean that the application can be executed on PostgreSQL, MySQL and maybe also Oracle SQL.)
Current idea is to leave the PDO DSN into the config file, so that the queries etc everything else stay the same, but can I face some problems in regards of CRUD actions to the tables themselves?
If I don't add any complex stuff in it, then is it possible for me to make it so that it doesn't depend on the engine at all, only has the PDO DSN for the database and that it can query everything the same way on each of the SQL engines?
Best regards!
Read about Database Abstraction Layer. There are quite some libraries available for PHP. If you choose any of the popular frameworks, to mention Symfony or Laravel - you will have the DBAL out of the box - either Doctrine or Eloquent. Both offer similar query building functionality, IMO based on HQL.
Definitely don't try to write it "your way". Even if you do only simple queries the gramma is different, to mention just the types, incrementing etc...
If you stick to a common subset of SQL which is supported by all your targeted databases, then yes, you can get away with using the same PDO instance, the same queries, and just switching the PDO DSN.
Practically speaking however, for anything but the most trivial queries, you'll probably be using some database specific features which you'll have to implement slightly differently for different databases. Simply speaking that means your code will have to execute query A if connected to MySQL but a slightly different query B if connected to Postgres.
You certainly do not want to implement that using a lot of if..else, instead you want to be using database specific adapters/drivers. In your business code you'll be calling $database->getUserRecords(), and depending on whether $database uses the MySQL or Postgres adapter the query will be slightly different. (Also see dependency injection.)
You can either do this by implementing those adapters by hand and tweaking the queries for each database, or use a more abstracted ORM/DBAL which can assemble the correct query on the fly using database-specific query builders. There are many existing libraries for that.

Should a PDO script written for MySQL work with Oracle? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I understand that in general PDO scripts are cross compatible i.e. generally changing the connection string should work.
In the past I've spent hours searching online after changing a PDO script connection string from MySQL to SQLite as this isn't the case, some things don't work the same (I remember an issue with row counting or something).
So should changing from MySQL to Oracle be generally simple, or are there things to watch out for as in the SQLite case?
So should changing from MySQL to Oracle be generally simple, or are there things to watch out for as in the SQLite case?
There are things to watch out.
More seriously, beside basic SQL query, each RDBMS has its own set of specific features that have to be taken into account. Just to give one example, if you want to limit the result set to one row only, MySQL provides the LIMIT clause. But for Oracle up to 11g, you need a sub-query for that purpose.
If you really need cross-vendor support, you probably should take a look at some library providing database abstraction layer whose job is to allow you to write database-agnostic code. PDO isn't such a library. But Doctrine DAL, Zend_db and many other are.
It is now considered as off-topic to request suggestions for a tool here, but take a look at this old question if you need few pointers: Best PHP DAL (data abstraction layer) so far

What is PHP Data Objects (PDO)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am relatively new to PHP. I have written some scripts using Oracle and MySQL as databases, using oci_ and mysqli_ but now I am trying to understand what exactly PDO is.
I have read the PDO documentation at http://www.php.net/manual/en/book.pdo.php but still I have a few questions that I'm not sure on.
If I wanted to write a script to connect to an Oracle database I could use oci_ functions, and then if I wanted to use the same script to connect to a MySQL database I would have to convert the script to use mysqli_ functions.
Is the point of PDO that the same script can be used for any database, and the only part that would need to be changed is the DSN?
Is the point of PDO that the same script can be used for any database,
and the only part that would need to be changed is the DSN?
From the manual: Introduction http://www.php.net/manual/en/intro.pdo.php
The PHP Data Objects (PDO) extension defines a lightweight, consistent
interface for accessing databases in PHP. Each database driver that
implements the PDO interface can expose database-specific features as
regular extension functions. Note that you cannot perform any database
functions using the PDO extension by itself; you must use a
database-specific PDO driver to access a database server.
PDO provides a data-access abstraction layer, which means that,
regardless of which database you're using, you use the same functions
to issue queries and fetch data. PDO does not provide a database
abstraction; it doesn't rewrite SQL or emulate missing features. You
should use a full-blown abstraction layer if you need that facility.

Lost in how to start learning databases with php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I was developing a website and learning how to code at the same time. So far I just got the hang of PHP. And now i want to learn how to integrate databases with PHP. Do i start learning MySQL and its libraries? I've been reading that PDO are the way to go and I'm just lost on what order I should be learning things.
Mysql is a database. Completely different thing. One is supposed to learn basic Mysql separately, independently from PHP or any other language, practicing basic queries in console or whatever GUI client.
Once you make yourself familiar with basic SQL, you can turn to running basic queries from PHP using PDO. Only static queries without variable parts.
And finally, you may start for building dynamical queries using prepared statements. Basic info on PDO you can find here in the tag wiki
You have a very open-ended question.
However, typically with PHP the standard is MySQL so I would suggest you learn that. Furthermore, most SQL is similar in syntax. Typically when working in PHP you will use MySQL, PostgreSql or SQLlight. They all have very similar syntax.
I suggest you find a book on PHP/MySQL and study that. I typically don't endorse books, but there is a great book for beginners by Head First called, "Head First PHP & MySQL". You will learn a lot with that book, you can google it as I don't know the link.
Furthermore, php.net is your best resource for PHP-related programming.
One final tip, I suggest you learn the Object-oriented way to program in general including opening your database connection as procedural-style is going away.
Good luck! And I am happy you are going with PHP and aren't another .net drone.
(also, download cake.php or codeignighter to learn about building lightweight, well-designed frameworks)
I would start in following order:
Create basic table and input some value through phpmyadmin
example: do one for users. create table named "user" and columns "user_id","username","password", "email"
Use SELECT statements to select certain data through phpmyadmin
Build simple php page with connection and retrieve your db data
Learn about SQL injections and security issues learn Object Oriented Programming for PDO use (optional)
Start transferring your traditional mysql into PDO type
and then start learning mysql more in depth
Good Luck!

PHP PDO vs normal mysqli speed performance benchmark [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
i m working on a project about social networking website where speed optimization is very critical.
is PDO is FASTER ?
i am thinking to switch to PDO is it recommended for use PDO for such a site ?
I doubt using PDO or MySQLi will be bottleneck, though, if you ask for bechmarks, here they are (nothing serious, just couple of tests).
In general, using one or another is a matter of taste, and bottlenecks usually are somewhere else (e.g., queries, indexes, PHP code etc).
One thing you might consider is using some DB wrapper, i.e., class that uses either PDO or MySQLi, whichever you prefer. In your code, use this wrapper instead of using PDO or MySQLi directly. If you do this, you'll be able to switch between PDO, MySQLi or any other library by changing single class instead of changing all the code.
I did a mini benchmark on this a while back. Conclusion. PDO and MySQLi are very similar but the features in PDO are worth using.
http://cznp.com/blog/2/apples-and-oranges-mysqli-and-pdo

Categories