Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-16-2007, 07:23 AM
Junior Member
 
Join Date: Aug 2007
Posts: 10
Default ADODB VS Zend_DB ??

I just kick start a new project which using the Zend Framework
One of my teammate suggested to use ADODB instead of Zend_Db as the database abstract layer. Of cause, I am just a newbie in Zend Framework and ADODB idiot, so I don't know what are the pros and cons between them ~

Q1: What is the pros and cons of Zend_Db compare with ADODB
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-16-2007, 09:24 AM
Member
 
Join Date: Aug 2007
Location: Tarnow/Krakow, Poland, EU
Posts: 30
Default

Adodb is pretty slow, especially when you don't have Adodb extension installed. I've been using Adodb for a long time beacause it makes database handling very easy, but I wouldn't use it with Zend Framework. Zend_Db is great choice for database handling too and it's faster and more portable then Adodb.
__________________
I don't trust anything that bleeds for five days and doesn't die.
www.inetive.pl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-16-2007, 10:18 AM
Junior Member
 
Join Date: Aug 2007
Posts: 10
Default

Hi borec, thank you for your reply

I have search after I posted this thread and I have questions about your statement.

Would you mind to tell me more details about the reason of Zend_db faster than Adodb and more portable ?

Firstly, I don't agree zend_db is more portable.
I think the adodb is more portable because it independent with the framework, which mean that we just plugin and play the database and adodb into new framework when we wanna change the framework. If my opinion is not true, please let me know

On the other hand, is it possible to implement active record in Zend_db by ourselves ?

Last edited by GeniusTse : 08-16-2007 at 10:26 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-16-2007, 11:35 AM
Member
 
Join Date: Aug 2007
Location: Tarnow/Krakow, Poland, EU
Posts: 30
Default

Why faster? Well, first of all, adodb is written in about 28702 lines of code and Zend_Db in about 2000. Also, Zend_Db is written entirely for PHP5 and Adodb for PHP4, which is much slower.

Why more portable? It's not so easy to switch to another RDBMS with Adodb, you have to write with some things in mind (see Tips on Writing Portable SQL for Multiple Databases for PHP). With Zend_Db, you can just change adapter and it works.

Quote:
I think the adodb is more portable because it independent with the framework, which mean that we just plugin and play the database and adodb into new framework when we wanna change the framework.
You can do exactly the same thing with Zend_Db. In fact, you can use every of Zend Framework components as a stand-alone component for any of your application not built using ZF.

Quote:
On the other hand, is it possible to implement active record in Zend_db by ourselves ?
Why not? You just have to know how
__________________
I don't trust anything that bleeds for five days and doesn't die.
www.inetive.pl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-16-2007, 12:43 PM
Junior Member
 
Join Date: Aug 2007
Posts: 10
Default

Thank you, your reply is very helpful

I have one more question about the portability of the Zend_Db.

I know that Zend has an Class, Zend_Db_Expr which allow to use SQL function inside a SQL statement. But, sometimes, there are some SQL functions were supported in specified DBMS. If I applied an expression / functions which is not supported by others DBMS, does Zend_Db_Expr will resolve this heterogeneous problem ? If not, how can I prevent this problem to make the database more portable ?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-16-2007, 01:10 PM
Member
 
Join Date: Aug 2007
Location: Tarnow/Krakow, Poland, EU
Posts: 30
Default

Quote:
Originally Posted by GeniusTse
I know that Zend has an Class, Zend_Db_Expr which allow to use SQL function inside a SQL statement. But, sometimes, there are some SQL functions were supported in specified DBMS. If I applied an expression / functions which is not supported by others DBMS, does Zend_Db_Expr will resolve this heterogeneous problem ? If not, how can I prevent this problem to make the database more portable ?
Zend_Db uses PDO, therefore this is also true when using it:
Quote:
Originally Posted by PHP documentation
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.
So if you want your application to be completely portable, you should avoid using pure SQL statements in your code (with Zend_Db_Statement, not Expr). Instead, use only abstracted classes like Zend_Db_Table.

Of course, if you want to use some features that are supported by one of the DMBS but not by others, you could write your own abstraction to this feature that will emulate it for DMBSs not supporting it.
__________________
I don't trust anything that bleeds for five days and doesn't die.
www.inetive.pl
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-17-2007, 02:19 AM
Junior Member
 
Join Date: Aug 2007
Posts: 10
Default

If we are using the pure abstract class, Zend_Db_Table, it seems inefficient when I want to join tables. Refer to the Reference Guide - Zend Framework: Documentation,
PHP Code:
/*line 1*/ $accountsTable      = new Accounts();
/*line 2*/ $accountsRowset     $accountsTable->find(1234);
/*line 3*/ $user1234           $accountsRowset->current();
/*line 4*/ $bugsAssignedToUser $user1234->findDependentRowset('Bugs''Engineer'); 
it joins Accounts to Bugs with two find method (line 2 and line 4)

Q1: Does it open&close database connection 2 times or just 1 ?
Q2: Compare with pure SQL, how's the performance of this style to query databases?

Please forgive my foolish and poor english
LoL
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-17-2007, 08:37 AM
Junior Member
 
Join Date: Aug 2007
Posts: 2
Default

I cannot answer your questions right away but to effectively see if two connections are opened and how the SQL output looks like, I recommend working with the log files of your database if this is possible.

This way you can exactly see how often a connection is opened or which queries are issued to the database.

About the performance of this query style: This heavily depends on the SQL output when using Zend_Db_Table and more or less about how you design your database.

In general no one can say right now that Zend DB is faster than AdoDB because there are no real benchmarks out yet. Just less code lines and PHP5 do not make a DB abstraction faster.

For example: I recognized that ALL queries using Zend_Db_Adapter are prepared. This sounds like a good idea, but in fact it isn't.

When you're doing a simple insert query:

PHP Code:
<?php
$data 
= array(
    
'created_on'      => '2007-03-22',
    
'bug_description' => 'Something wrong',
    
'bug_status'      => 'NEW'
);

$db->insert('bugs'$data);
the query is prepared first and then executed which ends up in TWO SQL queries send to the database server. Now imagine inserting 20.000 rows in a loop = 40.000 db queries with a huge amount of prepare overhead.

Usually you would prepare the statement by yourself one time and then just change the values being issued and executed the former prepared statement, which is 20.001 queries Prepareing a statment is not bad, but in this case you're just not aware that it IS prepared and you have no chance to disable automatic prepares in ZF right now.

So I would suggest you do excessive benchmarks regarding the requirements of your application before you blindly trust a specific db abstraction. But one could say, usually the db design, correct indices and normalizing / denormalizing the db really matter.


About huge libraries like AdoDb or the Zend Framework:
you might also use eAccelerator: PHP Accelerator, optimizer, dynamic content cache - Trac which caches compiled PHP scripts and is especially effective when using a great amount of static include files which rarely change.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 08-29-2007, 02:43 AM
Junior Member
 
Join Date: Aug 2007
Posts: 1
Default

Quote:
Originally Posted by chriswest View Post
When you're doing a simple insert query:

PHP Code:
<?php
$data 
= array(
    
'created_on'      => '2007-03-22',
    
'bug_description' => 'Something wrong',
    
'bug_status'      => 'NEW'
);

$db->insert('bugs'$data);
the query is prepared first and then executed which ends up in TWO SQL queries send to the database server. Now imagine inserting 20.000 rows in a loop = 40.000 db queries with a huge amount of prepare overhead.

Usually you would prepare the statement by yourself one time and then just change the values being issued and executed the former prepared statement, which is 20.001 queries Prepareing a statment is not bad, but in this case you're just not aware that it IS prepared and you have no chance to disable automatic prepares in ZF right now.
While this is true it is possible to cache the table metadata removing the second query thus returning you to 20,000 queries

i.e.

<?php

// First, set up the Cache

require_once 'Zend/Cache.php';

$frontendOptions = array(
'automatic_serialization' => true
);

$backendOptions = array(
'cacheDir' => 'cacheDir'
);

$cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);


// A table class is also needed

require_once 'Zend/Db/Table/Abstract.php';

class Bugs extends Zend_Db_Table_Abstract
{
// ...
}


// Configure an instance upon instantiation

$bugs = new Bugs(array('metadataCache' => $cache));
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 08-29-2007, 08:27 AM
Junior Member
 
Join Date: Aug 2007
Posts: 2
Default

Sorry, maybe you understood me wrong or you just wanted to show how table metadata caching is achieved (which is nice!) - the problem I wanted to show lies deeper (within the adapter implementation) and has nothing to do with a table's metadata.

to pick up your example, if you do this:
PHP Code:
$bugs = new Bugs(array('metadataCache' => $cache)); 
This just solves the following "issue":
Quote:
By default, Zend_Db_Table_Abstract queries the underlying database for table metadata upon instantiation of a table object. That is, when a new table object is created, the object's default behavior is to fetch the table metadata from the database using the adapter's describeTable() method.
But, if you do a simple insert:

PHP Code:
$bugs->insert($data); 
The query will internally be prepared every time you call the insert method. The mysql log looks like this then:

PHP Code:
Prepare   INSERT INTO ...
Execute   INSERT INTO ... 
for every call to insert() query.

While this is good for Oracle database backends (which benefit from prepared statements) it really is a performance bottleneck regarding to MySql backends which do only benefit from a prepared statement if you prepare it once and then use it to insert e.g. 10.000 rows with the same prepared statement.

hope I was able to explain the problem

(just turn on your mysql log file if you use a mysql database, to see what really happens when using insert())
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 03:46 AM.