Jump to content

Archived

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

Zanjo

Need Function

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.

Share this post


Link to post
Share on other sites
I need to make this for a standard php install, without any addons.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
I tried that initially, but that script doesnt work in a while loop, as it forever returns the same result. I need it to function like the real fetch_array functions do in a loop.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites
Sorry, i meant not with extensions like adobd. Is there any way to make the Script that Barand posted work with the input just in sql? So it does the [database]_query in the function?

Share this post


Link to post
Share on other sites
If you put the query inside the function then it certainly will NOT work inside a while() loop as it will then re-execute the query every time you try to fetch the next row.

Share this post


Link to post
Share on other sites

×

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.