November 2006
Intermediate to advanced
977 pages
30h 42m
English
Has any database been selected as the default database? What is its name?
Use the
DATABASE()
function.
SELECTDATABASE() returns the name of the
default database or NULL if no
database has been selected. The following Ruby code uses the statement
to present a status display containing information about the current
connection:
db = dbh.select_one("SELECT DATABASE()")[0]
puts "Default database: " + (db.nil? ? "(no database selected)" : db)Note that before MySQL 4.1.1, DATABASE() returns an empty string
(not NULL) if there is no current
database.
Read now
Unlock full access