Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect database type?

I need to be sure the database I'm connecting to is MySQL and not PostgreSQL or Microsoft SQL Server.How can I find out which type of database is being used .

like image 336
BHY Avatar asked Aug 09 '26 12:08

BHY


1 Answers

The first hint might be the "connection error" you're likely to get if you try to connect to a PostgreSQL database with a mySQL database driver :)

Basically, you need to:

1) Code your application in a portable manner (don't use MSSQL extensions in a query that might be run on mySql, for example)

2) Choose a portable driver API (like JDBC, ODBC, ADO.Net, etc)

3) Provide some mechanism for your application to query the actual database type at runtime (for example, an .config properties file)

4) Test your completed application against each of the supported database types.

'Hope that helps .. PSM

like image 138
paulsm4 Avatar answered Aug 13 '26 06:08

paulsm4



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!