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
https://forums.phpfreaks.com/topic/11073-need-function/
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
https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41422
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
https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41615
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.