How many sql functions to support? Is all an overkill?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

How many sql functions to support? Is all an overkill?

Post by AlexC »

Hey,

I've set up an SQL Factory to use in my framework for an open-source cms I'm (still) recoding, I've got it all setup and it works fine. I'm using an interface to make sure that all SQL classes (be it MySQL, Postgre, SQLite, MsSQL ... ) have the required methods so that scripts don't break if the admin decides to switch from say MySQL to Postgre.

My problem is, how many/which sql functions do I support? Should I make it so every class has to have every mysql function (without the mysql_ perfix, so for example "mysql_connect" would be "connect" in my interface. I'm currently just building up the interface as I go along, here is what I have so far:

Code: Select all

// ---
	// iSql is the interface that _all_ SQL classes _must_ implement to make sure that
	// there is no missing methods that could potential break a script from switching 
	// from MySQL to say Postgre.
	//---
	interface iSql {
		
		public function connect( $host, $user, $pass, $database );
		public function smart_clean( $value );
		public function query( $query, $output=false );
		public function fetch_array( $result );
		public function num_rows( $result );
		
	}
It's a small list for now, is adding all the functions an overkill?

Regards,
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I don't think that is too small a list. There are several more like: transaction start, commit, rollback, and last insert id that are pretty standard. Also, you might want to look at the many classes that already exist or new ones like the Zend Framework's. There are a lot of little details with these things and your time is probably better spent elsewhere.
(#10850)
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Post by AlexC »

So what happens if someone wants to do "fetch_object" instead, or another function that I'm not supporting?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

AlexC wrote:So what happens if someone?
Who's someone?
AlexC wrote:wants to do "fetch_object" instead, or another function that I'm not supporting?
I usually support fetching associative arrays and objects.
(#10850)
AlexC
Forum Commoner
Posts: 83
Joined: Mon May 22, 2006 10:03 am

Post by AlexC »

What i'm coding this for is an open-source cms, so people can, if they want, develop new modules to expand the features my CMS can offer. What if when they are developing a module, need a sql function that I havn't supported?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Well they can always extend the class and access the link identifier in it. But I doubt anyone with use anything other than associative arrays and object results.
(#10850)
Post Reply