Ninjakreborn Posted October 12, 2006 Share Posted October 12, 2006 Is there a way to test what database servers/ or possibilities exist, like for portable code.Like if it's postgresql, then you can setup that connection, if it's another, then you do another connection.Is this possible.I wnat to build a function, that when you feed it the variables, the db location, username, password, and database to select. Then you have an optional parameter of database, but if you don't insert that, it checks to see the first one that is available for testing, sort of like auto-detect, or something. Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/ Share on other sites More sharing options...
HuggieBear Posted October 12, 2006 Share Posted October 12, 2006 You mean a way to query the database using a generic function to try and return the type, e.g. MSSQL, MySQL, Oracle, etc.Something like (obviously not real code):[code]<?php$type = db_type($username, $password, $server);echo $type;?>[/code]If so, then I don't think so, although that would be excellent. I think you'll need to create a custom function with each of the different connection methods, e.g.mysql_connect() - MySQLoci_connect() - Oracledba_open() - Berkeley DBodbc_connect() - Access etc..And then loop through until you get a successful response.RegardsHuggie[color=red][b]P.S[/b][/color] Did that other code I changed for you bring you any joy at all? Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/#findComment-107825 Share on other sites More sharing options...
AndyB Posted October 12, 2006 Share Posted October 12, 2006 I assume this is an intellectual exercise not a real problem, since it would be unlikely you would be writing code to access a database without knowing what database you were trying to access. Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/#findComment-107830 Share on other sites More sharing options...
HuggieBear Posted October 12, 2006 Share Posted October 12, 2006 It's possible... If you right a commercial script and you make it compatible with multiple databases but you want to provide an out install script with it or something. You might want to assume that the user doesn't know, the type, only the details of where it's located.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/#findComment-107832 Share on other sites More sharing options...
Ninjakreborn Posted October 12, 2006 Author Share Posted October 12, 2006 I am about to start a huge project, with a friend, he is wanting it to be heavily portable, so I was just going through available options I might go with pear:db Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/#findComment-107858 Share on other sites More sharing options...
redarrow Posted October 12, 2006 Share Posted October 12, 2006 The idear is nice but not pradical as all database have slight database code diffrences.i would erge you to consontrate on one database type.saying that i have done what your asking but using lots of functions for the database information and it was a right headake.but good luck businessman nice idear theo. Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/#findComment-107877 Share on other sites More sharing options...
Ninjakreborn Posted October 12, 2006 Author Share Posted October 12, 2006 That's why i said Pear:db, it allows you to support many databases, with just one set of functions. Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/#findComment-107895 Share on other sites More sharing options...
trq Posted October 12, 2006 Share Posted October 12, 2006 You might also look into using [url=http://php.net/pdo]pdo[/url]. In my experience it has been great, of course your locked into php5 > then though. Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/#findComment-107902 Share on other sites More sharing options...
Ninjakreborn Posted October 12, 2006 Author Share Posted October 12, 2006 Thanks, it gives me something new to play with. Quote Link to comment https://forums.phpfreaks.com/topic/23726-databasewithphp/#findComment-107910 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.