Jump to content

Need Function


Zanjo

Recommended Posts

Hi,
I need a function (lets call it dbarray) that can be like mysql_fetch_array or oci_fetch_array, but can work with multiple databases. For example, the database type (mysql, oci etc) would be in the variable $conf['database'].
The Second thing is, it needs to be able to used in a while loop
like
while ($data = dbarray(mysql_query($sql)))
{
statement;
}.
Thanks for your help.
Link to comment
Share on other sites

You need something like
[code]
function fetch_array ($dbtype, $result) {

     switch ($dbtype) {

         case 'mysql' : return mysql_fetch_array($result);

         case 'mssql' : return mssql_fetch_array($result);

         //etc
     }
}[/code]

Alternatively
[code]
function fetch_array ($result) {

     global $conf;

    $dbtype = $conf['database'];

     switch ($dbtype) {

         case 'mysql' : return mysql_fetch_array($result);

         case 'mssql' : return mssql_fetch_array($result);

         //etc
     }
}[/code]
Link to comment
Share on other sites

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]but that script doesnt work in a while loop[/quote]
Yes it does. Your might not have, but that one will.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I need to make this for a standard php install, without any addons.[/quote]
You do realise that in a [i]standard[/i] php install (ie; with no extensions) there is no support for MySql built in (or any other database for that matter)? What exactly do you consider to be addons?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.