Development Information

November 28, 2010

Potential Database Class Rewrite

Filed under: Updates — judda @ 4:51 pm

Hey guys,

Within the next few weeks I’m going to go into a complete recode for my database class. Because of this, I want to know if you guys can think of anything else which would make it even more powerful / that you would like to see implemented with it.

A few of the changes that I am thinking of are as follows:

i) Adding the ability to specify a location for a parameter to bind to – i.e. if I have a query where I am binding the same variable several times, i.e.

SELECT `username` FROM `trades` WHERE `ownerId` = %u OR `offerOwnerId` = %u

Where we are looking for everything from a single user (i.e. ownerId or offerOwnerId is one user’s user id). Currently you would have to bind it as:

$db -> query ( 'SELECT `username` FROM `trades` WHERE `ownerId` = %u OR `offerOwnerId` = %u', $userId, $userId );

I’m thinking of changing it so that you only need to provide the query function with $userId once. So now the structure of the query would be as follows:

SELECT `username` FROM `trades` WHERE `ownerId` = {0:u} OR `offerOwnerId` = {0:u}

Where the 0 is the element it will bind to the query (i.e. 0 is the first parameter, 1 would be the second and so on) then you could bind to the query like:

$db -> query ( 'SELECT `username` FROM `trades` WHERE `ownerId` =  {0:u} OR `offerOwnerId` = {0:u}', $userId );

ii) Change the parameter binding away from the use of the percent signs (i.e. %u) to using the curly braces (i.e. {u}). I could deprecate the use of the percent sign so anyone with the code written in the original format would receive deprecated warnings throughout their code when their queries are still running using the old syntax.

iii) Change all error messages to provide E_NOTICE when you have invalid parameters.

That is all I can think of for now. Anyone else have any suggestions on improvements?  If you do, please post them within the comments.


No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.

Powered by WordPress