|
-
Sep 20th, 2010, 02:04 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] [PHP] Database interface
Hi,
I'm building a database interface for my CMS.
Please correct me if I'm wrong: the purpose of such an interface would be that I could easily convert the database engine from one to another.
I have the following functions the interface:
- connect
- close
- select_db
- query
- num_rows
- fetch_assoc
- escape_string
- error
- errno
Am I missing anything important/useful?
Thanks
Last edited by TheBigB; Sep 21st, 2010 at 02:56 PM.
Delete it. They just clutter threads anyway.
-
Sep 20th, 2010, 02:30 PM
#2
Re: Database interface
try taking a look at CodeIgniter http://codeigniter.com/ look through their Database Class in the User Guide ... should give you a pretty good idea of what to look for.
-tg
-
Sep 20th, 2010, 07:03 PM
#3
Re: Database interface
yes -- the purpose of an interface is so that you can define the way a class should work, but leave the actual implementation up to the developer (either you, or someone else). so, then you can create a MySQL-based class and also an Oracle-based class, and all of the method names would be the same.
I would personally suggest writing methods that allow you to create prepared statements; they are absolutely invaluable and remove the chance of a user opening themselves up to SQL injection.
-
Sep 21st, 2010, 03:02 AM
#4
Re: Database interface
Have you considered using PDO?
-
Sep 21st, 2010, 05:04 AM
#5
-
Sep 21st, 2010, 05:22 AM
#6
Thread Starter
Frenzied Member
Re: Database interface
 Originally Posted by visualAd
Have you considered using PDO?
I haven't, but I might, now that I've read that.
Should I be worried about webhosters not having PDO enabled?
 Originally Posted by kows
I would personally suggest writing methods that allow you to create prepared statements; they are absolutely invaluable and remove the chance of a user opening themselves up to SQL injection.
I've never worked with them in PHP but I see PDO has support for prepared queries, so I might consider that.
 Originally Posted by techgnome
try taking a look at CodeIgniter http://codeigniter.com/ look through their Database Class in the User Guide ... should give you a pretty good idea of what to look for.
-tg
After a quick glance I at least found one function I really like;
Code:
$data = array(
'title' => $title,
'name' => $name,
'date' => $date
);
$this->db->insert('mytable', $data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('{$title}', '{$name}', '{$date}')
PDO would be awesome, but the only question that remains is scale of deployment.
Thanks for the suggestions so far.
Last edited by TheBigB; Sep 21st, 2010 at 05:33 AM.
Delete it. They just clutter threads anyway.
-
Sep 21st, 2010, 06:00 AM
#7
Thread Starter
Frenzied Member
Re: Database interface
Also, is it a good idea to design a front-end for PDO?
Delete it. They just clutter threads anyway.
-
Sep 21st, 2010, 07:50 AM
#8
Re: Database interface
May wish to add select_server.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Sep 21st, 2010, 12:00 PM
#9
Thread Starter
Frenzied Member
Re: Database interface
That's pretty much what connect is for.
Or do you mean something else?
Delete it. They just clutter threads anyway.
-
Sep 21st, 2010, 12:24 PM
#10
Re: Database interface
Your Interface looked similar to mine. I build the connect string from properties:
UserID property
Password property
DataBase property
Server Property
Then my connect method takes no arguments. I thought a server property would be nice if you can change the database. But if you're just connecting to Access then you may not need it.
VB6 Library
If I helped you then please help me and rate my post!
If you solved your problem, then please mark the post resolved
-
Sep 21st, 2010, 05:50 PM
#11
Re: Database interface
 Originally Posted by TheBigB
I haven't, but I might, now that I've read that.
Should I be worried about webhosters not having PDO enabled?
Web hosts should probably be worried that you'll find another host if they don't support it. I believe that most now do.
 Originally Posted by TheBigB
Also, is it a good idea to design a front-end for PDO?
It depends on the design pattern you are using. If you are using something like the model view controller pattern, your front end will be another layer of abstraction on top of the PDO layer. At minimum you should consider a simple templating class for the front end.
As well as PDO you also have Pear::DB (which is an abstract library similar to PDO) and Mysqli (which supports prepared and paramatized queries). Also, you can see the link in my sig for PHP5 OOP I have created a DB abstraction layer as an example.
There is little point in writing your though own if there is one that already exists and you don't have very bespoke requirements.
Last edited by visualAd; Sep 21st, 2010 at 05:55 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|