The company I work for currently uses some basic functions to abstract the OCI libraries as a means for DB connectivity. We're considering switching to PHP's PDO object, but from some quick searches, it looks like the Oracle driver is a bit less mature than the other PDO drivers. I would appreciate some pro/cons for PDO/oci8 from anyone who has used it in a production environment.
Thanks!
I don't have personal experience with the PDO driver (being tagged as experimental was enough for not even considering it). But in The Underground PHP and Oracle Manual we can read the following, as preface to the PHP PDO Extension chapter:
The PDO extension and PDO_OCI driver are open source and included in
PHP 5.1 onwards. Oracle does not contribute to PDO_OCI.
The PHP community has let the PDO project languish and Oracle recommends using
OCI8 instead whenever possible because of its better feature set,
performance, reliability and stability. Use of PDO_OCI for general
purpose applications is not recommended.
The extension is not finished, it's probably poorly maintained (although some bug fixes get through now and then) and it's been that way for years. I would not put my eggs in that basket.
It seems to me that Oracle is not interested in developing a driver for PDO it's developing it's own driver to keep you close to oracle database... to oracle driver... etc. :)
As far as I've seen there is no problem if you can cope with max. texts of VARCHAR2 of 4000 CHARS. If you need CLOBs (and/or bigger) don't go with PDO_OCI.
I've created a suite of classes "PDOSurrogate" as a drop in replacement for PDO with Oracle.
When PDO is mature enough I can use Refactor->Rename to change it to PDO.
May be I'm too late to the party .. just thought to add some value to the discussion. I am experienced in OCI8 and OCI8_11 extension and have done some extensive workload using stored procedures/packages, CLOB/BLOB's and XML I never had to run out of options .. further it seems very reliable and can handle extensive loads and I have even used once for an ETL(Extract Transform Load) applications to handle heavy workloads... also believe oci8 is the widely used extension .. than pdo ..
Related
There is a tutorial I'd like to follow which has some great reviews. The only problem being it makes use of MySQLi instead of MySQL. I only have access to MySQL.
Are there big enough differences to warrant looking for a straight PHP-MySQL tutorial or is it worth just going with this one and making changes myself?
I would say I am a 'beginner' with both PHP and MySQL, but can find my way around the code fine, apply CRUD etc so not completely new.
MySQLi is PHP's "improved" MySQL driver. Meaning it will take full advantage of MySQL servers version higher than 4.1.3.
Then underlaying MySQL server would be the same, using the old MySQL interface or the newer MySQLi, so everthing should remain valid if you are following a MySQL tutorial on a MySQLi interface.
In your case, you should pay attention to MySQLi only stuff since they won't be avaliable to you.
Quote from the official website:
What is PHP's mysqli Extension?
The mysqli extension, or as it is
sometimes known, the MySQL improved
extension, was developed to take
advantage of new features found in
MySQL systems versions 4.1.3 and
newer. The mysqli extension is
included with PHP versions 5 and
later.
The mysqli extension has a number of
benefits, the key enhancements over
the mysql extension being:
Object-oriented interface
Support for Prepared Statements
Support for Multiple Statements
Support for Transactions
Enhanced debugging capabilities
Embedded server support
It shouldn't be too hard to make the necessary adjustments. If you look at PHP's MySQL functions vs the MySQLi functions functions the main difference is that MySQLi is an object-oriented interface. Converting back to the regular MySQL functions is usually quite easy, for example: $rs->affected_rows becomes mysql_affected_rows($rs).
As #hexa pointed out, there are a couple things in MySQLi that the old interface doesn't support, such as prepared queries. If the tutorial involves those, it's not that hard to convert them to regular queries, it's just a bit of a hassle.
I have been looking for a very light weight PHP ORM library and I ran across a few good choices. Unfortunately, most choices require some form of
configuration, e.g. adding more fields to the class and many of them
are not so intuitive.
I do not want to use a framework, but prefer just the ORM for Q&D
prototypes.
Anyway, I started building my own PHP ORM library called SORM (Simple ORM). It is very much in alpha state. You can checkout the code and examples at
https://github.com/teraom/sorm
I would appreciate if you can provide some feedback or directions on
how to proceed, things to change etc.
I am interested in using mysqli for database queries, specifically for prepared
statements, so as to avoid SQL injection.
Is there a way to use prepared statements with regular PHP - SQL
functions? Or prevent SQL injection by other means?
http://us2.php.net/manual/en/ref.mysql.php
Is mysqli installed by default when you install PHP? (PHP 5.2 and
above)
I know very little about PDO. Is PDO installed by default in PHP 5.2 and above? Does PDO come into picture too?
Thanks,
Bharad
Is there a way to use prepared statements with regular PHP - SQL functions?
Only when supported by the regular functions. The decrepit "mysql" extension does not provide this functionality. Some others do, like the one for PostgreSQL.
Is mysqli installed by default when you install PHP? (PHP 5.2 and above)
This is not answerable, as it depends on how PHP was compiled (if it's a custom installation), or whether it was installed via a package manager. If it was installed through a package manager, then it's very likely that all database support might be in an optional add-on package. However, if mysql support in general is enabled, the "mysqli" extension should be available.
Is PDO installed by default in PHP 5.2 and above?
Same answer as before -- it depends on how PHP was installed. It's enabled by default when compiling, but it might not be available depending on package management.
In general, you can rely on PDO being available most of the time. When it's not, it's either going to be oversight on behalf of the sysadmin, or an intentional decision to disable it by an idiot manager.
A lot of modern PHP is built assuming PDO will be there. There's not too much harm in making adapters for both PDO and mysqli, as both have generally similar feature sets. Just watch out for the weird, weird way that bind_param works -- it expects one call with all of the things to bind, by reference. This tends to turn people off.
Another option: Instead of building on top of PDO directly, build on top of another wrapper. I don't want to get all Inception on you, but take a peek at Zend_Db. Yes, I know you don't want to use a framework, but take a look at it anyway. It has adapters for the various PDO flavors, mysqli, Oracle, and DB2. It's also quite comprehensive, and the query builder (Zend_Db_Select) is pretty handy.
There are lots of other options in this area, like good old PEAR MDB2, which uses emulation to fake prepared statements and placeholders.
Both seem to try making it simpler using a database in PHP. Both seem to provide an abstraction over different database types like MySQL, SQLite, etc.
What are the differences between both ADOdb and PDO?
PDO is standard in PHP as of version 5.1. (It is also available with a PECL extension in PHP 5.0) Most hosting provides will have it enabled. AdoDB is not a standard extension.
Also, I believe the PDO drivers are "PHP-native": they are built on top of the same libraries that PHP itself was built on, and use the same underlying routines for things like memory management. So potentially, PDO is more lightweight than AdoDB.
According to this benchmark, AdoDB is considerably slower than PDO: (fixed link)
https://gist.github.com/tony-landis/31483
Of course, you should consider whether this is important enough for your use case to prefer PDO or not.
From a technical perspecitve, the most notable difference would be that PDO is a native extension and, from PHP 5 on, always included in PHP in its fast, compiled form. There is an extension for ADODb as well but you have to install it in PHP first. This is a strong argument in favour of PDO because products based on it are likely to run faster in more environments.
ADOdb supports a larger number of databases than PDO.
Well, I think it boils down to preference. ADOdb is more geared towards people who are used to the Microsoft style of Database access (ADO) and PDO is more "PHP" like and also part of the mainstream of PHP versus ADOdb which sort of sits off to the side.
At the end of the day, it would based on what your target DB is (ADOdb supports more) and what sort of language style your prefer. Personally, I like PDO and it suits my needs.
PDO is native and pretty fast.
ADOdb is a richer library and even has things like ORM (Object Relational Mapping).
For me the big downside of PDO is it's horrible to debug when it goes wrong as there's no PHP source for it. When I was debugging some complicated code the only way I could see the exact SQL that was being executed was the subclass the PDO driver itself...
It's all opinion though of course!
I've been using ADODB for PHP on several projects for quite some time, and I like it for the ease of use and the efficiency.
I've never been too curious about the way that lib accesses data because you know...it just worked :) But today I realized I'm still relying on the legacy MySQL4 ADODB drivers. I'm using MySQL 5.x, and it would probably be better if I started using a recent driver with ADODB.
But there are two drivers I could use :
adodb-mysqli.inc.php
adodb-pdo_mysql.inc.php
From what I read mysqli is pretty similar to the old mysql extension, optimized for MySQL5, while PDO is a layer between PHP and various DB systems (including MySQL of course).
Which one of these driver do you use ? Which one do you think I should use, and more importantly why should I prefer mysqli over PDO_mysql (or the opposite) ?
Answer : After a few days and some deep code reading, I ended up using the "adodb-mysqli.inc.php" driver. On a kinda-trafic-heavy site, I noticed the DB load went slightly down, and the network trafic between the web server and the db server went down by about 6.5%, which is good.
The PDO-mysql driver is probably pretty good too, but as said below, it doesn't make much sense to use ADODB over PDO. So mysqli it is.
All tests point towards PDO being the most efficient and the fastest driver. I do not know, however, if it makes sense to use PDO over AdoDB
I may be wrong but from what I remember of looking at the drivers, binding of variables in statements is emulated in the adodb mysqli driver despite the mysqli extension supporting binding. The pdo_mysql driver does however do the binding using the extension, so if you are using this you may get better performance.
Also might be worth adding that I think if you want to use the pdo drivers with adodb you have to use a different connection syntax and pass a DSN, there was an example in the docs. I struggled to get it to work for a bit because I didn't read this.
Almost all of free web hosting server,
you can not use PDO + MySQL.
They lack PDO drivers.
So I am considering to select
pear MDB2,
or DB_DataObject.
Which do you reccomend to me?
Give me your opinions!
I would actually recommend using the Mysqli functions if you can. They are fast, well-documented and well supported by the php community at large.
If you are looking for a more robust database abstraction layer, I would first suggest that you look at any of the excellent library's out there like DataMapper, or Propel or Doctrine, or even using the necessary portions of a framework like Zend. As further note, I've used Adodb in the past, but haven't seen much support for it recently.
I've used MDB2 quite a bit but have found the built-in mysqli functions to be fast and easy-to-use, plus they can integrate easily into a roll-your-own db abstraction layer.
DB_DataObject depends on MDB2, so you have to have it anyway.
The question is : do you need just bare database independence or more advanced ORM (that's DB_DataObject).
I'd suggest you stick with MDB2 since you seem confused about this stuff.
You can use DB_DataObject with MDB2 without problems.
ADOdb is also good.
The PHP version currently supports an amazing number of databases, thanks to the wonderful ADOdb community: MySQL, PostgreSQL, Interbase, Firebird, Informix, Oracle, MS SQL, Foxpro, Access, ADO, Sybase, FrontBase, DB2, SAP DB, SQLite, Netezza, LDAP, and generic ODBC, ODBTP. The Sybase, Informix, FrontBase and PostgreSQL, Netezza, LDAP, ODBTP drivers are community contributions.