PHP PDO vs normal mysqli speed performance benchmark [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 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

Related

Best driver for PHP database [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 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.

Databasing in Ruby [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 7 years ago.
Improve this question
I'm making a website for a group that needs a database. The data is going to store user information among other things. I already know PHP and could easily do it in PHP, but to further myself as a developer, I'd like to learn a language like Ruby. I know how to use databases in PHP. But, when writing Ruby, can I use SQL databases?
We don't know how you call your database in PHP.
Many PHP users use MySQL and call sql statements with the embedded mysql driver,
and then iterate over the results.
You can do this also in Ruby. The mysql driver is not embedded, But you can easily install it with RubyGems. You need the mysql2 gem.
https://github.com/brianmario/mysql2
But if want to be more object-oriented, there is the framework "Ruby On Rails" with "ActiveRecord" for database connection. Here you don't write SQL directly, instead you specify what objects you want to have or store (except in rare edge cases, where you still can write sql)
This needs some learning time. But then it is lot less coding, code is better readable, and security errors like are also easier to avoid.
The basic answer is yes - you can do something like that using Ruby and a framework like ActiveRecord or Sequel, but this far too broad for StackOverflow.
Good afternoon.
Depends on the speed you need .
1) If you need quickly - write on PHP
2) If you have some time and want learn Ruby On Rails, ActiveRecord etc. ... buy some book for beginner, read doc and step by step create application

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

MySQLi and PDO Connection in PHP [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I was a MySQL PHP coder, but then I realized that is vulnerable to SQL Injections and mysqli_* functions are deprecated, I decided to move on to some other way. I was wondering what is better, MySQLi or PDO?
What is the Most Secure?
What is quick in loading up data?
What is not vulnerable/least vulnerable to SQL Injections?
What is most popular and is preferred by the community?
I need help with these 4 questions and I am here to get them answered. I hope I will find high quality answers.
All three APIs are equally safe, quick and invulnerable.
PDO is preferred by the community because it's being a semi-DAL (Database Access Library) already, while both mysqli and mysql are just raw APIs that shouldn't be used as is but only as a build material for such a library. And because community has no desire/education/habit to create one out of two latter APIs, PDO is left as the only choice.
As an old school programmer you need to know only two things
Every variable should never go into query directly but via placeholder only
unlike mysql, PDO require a connection variable to be always available. Means you need to learn what variable scope is and how to access a global variable.

Changing this from MySQL to MySQLi? [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 7 years ago.
Improve this question
I've decided to switch to MySQLi, because some people have told me it's more secure.. What I'm really confused about, is the new extensions. I tried just added 'i' after every mysql, but that gave me a crap load of errors. I looked up in the PHP manual why that was happening and there was a whole bunch of other functions.. I honestly can't figure out how to convert. Can you help me out?
include("dbinfo.php");
mysql_connect($c_host,$c_username,$c_password);
#mysql_select_db($c_database) or die(mysql_error());
$mycon = new mysqli($c_host, $c_username, $c_password, $c_database);
$query="SELECT * FROM users WHERE username='" .$_COOKIE['username']. "'";
$result=mysql_query($query) or die(mysql_error());
$num=mysql_numrows($result);
$username=mysql_result($result,$i,"username");
Here's what you need to do:
Read the overview so that have an understanding of the differences/advantages.
Consult the old -> new function summary on the PHP site and get your existing code up and running with the mysqli interface.
Take advantage of the improvements (such as using prepared statements) otherwise this is a futile exercise. (By default mysqli really isn't any more secure than mysql.)
One of the reasons MySQLi is more "secure" is because it offers a different interface, which is better in many ways. Instead of trying to translate your code directly, learn the new interface and use it. If that's all your code, it wouldn't be easy to rewrite from scratch, and which is more important, look up the equivalents (and alternatives) for everything you're doing in the code that you pasted.
For starters, you should use $mysqli->prepare with parameters instead of interpolating variables like you're doing.
http://www.php.net/manual/en/mysqli.prepare.php

Categories