Jump to content

Archived

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

Ninjakreborn

database(withphp)

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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() - MySQL
oci_connect() - Oracle
dba_open() - Berkeley DB
odbc_connect() - Access etc..

And then loop through until you get a successful response.

Regards
Huggie

[color=red][b]P.S[/b][/color] Did that other code I changed for you bring you any joy at all?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Regards
Huggie

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites
That's why i said Pear:db, it allows you to support many databases, with just one set of functions.

Share this post


Link to post
Share on other sites
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.

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.