Jump to content


Photo

Need Function


  • Please log in to reply
7 replies to this topic

#1 Zanjo

Zanjo
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 03 June 2006 - 06:50 AM

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.

#2 Vikas Jayna

Vikas Jayna
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts
  • LocationNoida, Delhi, India

Posted 03 June 2006 - 08:48 AM

You can explore the php adodb library.
Vikas Jayna,
Project Manager - Jeevansathi.com
7 yrs. exp. in LAMP
Certified Mysql DBA
Zend Certified Engineer

#3 Zanjo

Zanjo
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 03 June 2006 - 08:52 AM

I need to make this for a standard php install, without any addons.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 03 June 2006 - 10:53 AM

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

     switch ($dbtype) {

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

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

         //etc
     }
}

Alternatively
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
     }
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Zanjo

Zanjo
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 03 June 2006 - 11:58 PM

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.

#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 June 2006 - 02:01 AM

[!--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 standard 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?

#7 Zanjo

Zanjo
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 June 2006 - 07:27 AM

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?

#8 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 04 June 2006 - 10:10 AM

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.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users