docs.roxen.comBack to normal mode
DocsRoxen2.2TutorialsDatabase Tutorial
Copyright  2004, Roxen Internet Software
Suggestions, comments & compliments

Database Creation

Database creation is not a part of the SQL standard, and the details are very much server-specific. The Pike SQL interface, however, offers two functions as part of the Sql.sql object that can serve for this purpose.

Create a "foo" database:

void create_new_database(string dbname) 
  mixed error;
  object db = Sql.sql("mysql://admin:password@localhost/");
  error = catch {
    werror("Error: "+db->error()+"\n");

Delete the "foo" database:

void delete_database(string dbname)
  object db = Sql.sql("mysql://admin:password@localhost/");

Of course the catch {} clause in the first example is overkill here, these operations are really REALLY meant to be used interactively, and so a stack backtrace can be very descriptive and useful.

Most servers provide an SQL syntax to perform this operation. In some cases creating a database is so expensive that an external app is used to perform the operation. When your server supports it via SQL, using SQL is advised. This functions are provided mostly for MiniSQL compatibility (MiniSQL doesn't provide an SQL syntax to create a database).