Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check database exist

Status
Not open for further replies.

michelleqw

Programmer
Joined
Jan 4, 2004
Messages
120
Location
DE
Dear PHP users,

Is there any posibillity to check or a database exist? If yes can someone give us source code?

Nice regards,

Michelle.
 
PHP can use native communications libraries to connect to a number of database servers, and can use ODBC to connect to a myriad more. What database are we talking about?



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Hallo sleipnir214,

Thanks for your reaction, my question was wrong: we want to test or a table excist.
We looked to the MySQL functions, but we could not find a solution.

Maybe you can help us.

Nice regards,

Michelle.
 
Without knowing the the database type, answering the question was not possible -- there will be different ways of doing this depending on the database.



I needed to determine whether in MySQL a table named 'foo' existed in a database named 'bar', I would issue the query SHOW TABLES FROM bar LIKE 'foo'

The query will return a single-column result set just like the return of a SELECT statement. I could then use mysql_num_rows() to determine whether the table was found.

Since the LIKE operator is available here, I could also have tested for all tables whose names begin with "foo" (tables foofoo, foobar and foobaz, for example), using the query "SHOW TABLES FROM bar LIKE 'foo%'" and looping through the return.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
or try a duff query e.g.
select vvv from tab where vvv=1, will return differing error codes depending on whether the table exists or if it does whether the column exists. Just make sure you use a bizare column name in case you strike lucky !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top