Zanjo Posted June 3, 2006 Share Posted June 3, 2006 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 looplikewhile ($data = dbarray(mysql_query($sql))){statement;}.Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/11073-need-function/ Share on other sites More sharing options...
Vikas Jayna Posted June 3, 2006 Share Posted June 3, 2006 You can explore the php adodb library. Quote Link to comment https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41405 Share on other sites More sharing options...
Zanjo Posted June 3, 2006 Author Share Posted June 3, 2006 I need to make this for a standard php install, without any addons. Quote Link to comment https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41407 Share on other sites More sharing options...
Barand Posted June 3, 2006 Share Posted June 3, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41422 Share on other sites More sharing options...
Zanjo Posted June 3, 2006 Author Share Posted June 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41600 Share on other sites More sharing options...
trq Posted June 4, 2006 Share Posted June 4, 2006 [!--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? Quote Link to comment https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41615 Share on other sites More sharing options...
Zanjo Posted June 4, 2006 Author Share Posted June 4, 2006 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? Quote Link to comment https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41644 Share on other sites More sharing options...
Barand Posted June 4, 2006 Share Posted June 4, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/11073-need-function/#findComment-41658 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.