Search code examples
phpadodb-php

Create a Database with ADOdb Active Record for PHP


I'm trying to use ADOdb for PHP for the first time and I'm having trouble trying to find out how to create a new database.

This is the code I have so far.

include_once('adodb/adodb.inc.php');
include_once('adodb/adodb-active-record.inc.php');
include_once('adodb/adodb-exceptions.inc.php');
$db = NewADOConnection('mysql://'.$username.':'.$password.'@localhost/'.$newdb);
ADOdb_Active_Record::SetDatabaseAdapter($db);

The error I get:

PHP Fatal error:  Uncaught exception 'ADODB_Exception' with message 'mysql error: [1049: Unknown database 'test'] in CONNECT(localhost, 'root', '****', test)'

I know the database doesn't exist, I want to know how to create it via code. Thanks.


Solution

  • Create an empty holding database and connect to it. then, if you're user has the permissions, run a create script.

    As a reminder, being able to execute dba scripts over the Web has inherent security issues. Please be careful.

    Thanks