Forum Moderators: coopster
include ("$mysql_connection.php");
$sql = "SELECT * FROM table";
$rows = [b]mysql_query[/b]($sql);
$row = [b]mysql_fetch_array[/b]($rows);
.
.
.
I'm not necessarily looking for direction, just your thoughts or maybe your development style if you have made this type of consideration.
Dpeeneding on how much code you do, it might be worth it to write such an interface.
For example: sendQuery('SELECT * FROM table');get_row; and so on, and then write a different set for each engine. Of course, in my case I have a table cahce and access part in the middle.
As I said, it all depends on how often you do cross engine development and if you want to invest the time.
SN
it might be worth running a search on n-tier architectures on Google. If I remember correctly, PHP Builder had a decent article.
I run a 3-tier system:
Tier 1:
Regular HTML pages that make calls to tier 2 for any dynamic content.
Tier 2:
Library functions that return formatted HTML to tier 1 and request data (in the form of arrays, variables and objects) from tier 3.
Tier 3:
API tier made up mostly of data access functions that access the database.
A couple of sample tier 3 functions:
// MySQL fetch associated array
function api_fetch($result)
{
$row = mysql_fetch_array($result);
return $row;
}
// MySQL get number of_rows
function api_num_rows($result)
{
$num_rows = mysql_num_rows($result);
return $num_rows;
}
Very simple, but if I change database, all I need to alter are the tier 3 functions.
There will be a performance hit for having this sort of portability, but it will be very minor. Apparently the performance hit of the PEAR functions is more significant, as they need to be all things to all men.
[edited by: jetboy_70 at 5:46 pm (utc) on Nov. 3, 2003]
I wrote a simple library a few years ago to do this... but having only really used MySQL in anger with PHP am concerned that my library will not be quite as portable. If I was starting a new large project then I would look seriously for a third party library.
With smaller stuff, up to about 10 or 20k lines, it is a lot simpler, for me, to change a bunch of lines and save the hit in process.
BUT, as with all things, it depends on the situation.