View Full Version : AdoDB?
Zegg90
02-13-2006, 07:09 PM
Does anybody know AdoDB?
I am learning to use it right now, instead of using the native PHP functions...
What are the advantages and disadvantages of using adodb instead of the php functions for mysql?
I use it for most of my development, as it's main benefit is allowing simple switching between different databases. Most of the things I use are with PostgreSQL, but occasionally I have to (under duress normally...) use MySQL, and rather than having to remember to switch between the different PHP functions, I can just ignore the details of the databases and worry instead about coding.
The cache functions are quite nice as well, for content-managed websites (as an example) you obviously want dynamic content, but having it update only every 5 minutes (say) could be perfectly acceptable.
A common task is checking for the existence of something within the database, the GetOne function of ADODB means this is a one-liner.
'Replace' means that 'Create' and 'Edit' pages can run off the same code, and passing an array of the data rather than crafting the VALUES(... or multiple SET arguments makes life a lot easier.
It can handle pagination for you as well, another common and potentially time-consuming task.
In all, it's damn useful and I'm glad I found it.
Zegg90
02-14-2006, 08:03 PM
Thanks for your reply...
I am stil learning adodb, and I have only gotten the grasp of using execute, autoexecute, fetchrow and a few other small ones...
What did you mean by the getone function, and the 'Replace'?
I also have a question about my usage... I want to select a row from a table, and I normally use something like this:
$var2 = $db->execute("select `id` from `users` where `id`=?", array($id));
$var1 = $var2->fetchrow();
Somebody else had said that when you use execute(), it does a fetchrow automatically... But when I take out the fetchrow line, it doesn't work... SO do I really need to use fetchrow, or am I doing something wrong with the execute?
If you're selecting just one field, and you expect your result-set to be one line (as searching by ID would hopefuly imply)
then you can do:
$id=$db->GetOne('SELECT id FROM users WHERE id='.$id);
Replace takes a table-name, an array and the name of the primary key as its arguments, and will use them to try and update the table. If this fails (i.e. the result doesn't exist) then it will insert a new record. If efficiency is your top priorirty, then it should be avoided as there will probably be better ways (the context of your code) to determine whether you should be updating or inserting, but it's very convenient.
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.