How to create DATABASE with phalcon

Hello friends, I am trying to create an open source project with phalcon. I am trying to create a database with phalcon codes like wordpress and drupal, that how on installation page they create even database something like 'CREATE DATABASE IF NOT EXISTS database' or like that. So when I try to fire code

$this->db->execute('CREATE DATABASE IF NOT EXISTS database');

its not working so can anyone tell me how can I create database within phalcon controller?

Thank you.

See point #2 > http://codex.wordpress.org/Installing%5WordPress#Famous%55-Minute%5Install

But I don't know why Wordpress asks for manual database creation like that.

But there is also automatic wp installation which creates wordpress database and installs it. Thtat is what I wanna do with Phalcon. ;) Thanks for help.

See point #2 > http://codex.wordpress.org/Installing%5WordPress#Famous%55-Minute%5Install

But I don't know why Wordpress asks for manual database creation like that.

edited Dec '14

Just tried this in a controller, it worked, database can be seen from PhpMyAdmn

$re = $this->db->query("CREATE DATABASE `testtest`");
if ($re) {
    echo 'CREATED';
} else {
    echo 'COULD NOT CREATE';
}

But this will not:

$query = new Phalcon\Mvc\Model\Query("CREATE DATABASE `testtest2`");
$result = $query->execute();

With error:

CREATEDSyntax error, unexpected token IDENTIFIER(CREATE), near to ' DATABASE testtest2', when parsing: CREATE DATABASE testtest2 (27)

Okay, I will try this caz I was doing execute insted of query. ;) thanx for heads up @Edward

Just tried this in a controller, it worked, database can be seen from PhpMyAdmn

```php $re = $this->db->query("CREATE DATABASE testtest"); if ($re) { echo 'CREATED'; } else { echo 'COULD NOT CREATE'; } ``` But this will not:

```php $query = new Phalcon\Mvc\Model\Query("CREATE DATABASE testtest2"); $result = $query->execute(); ``` With error:

CREATEDSyntax error, unexpected token IDENTIFIER(CREATE), near to ' DATABASE testtest2', when parsing: CREATE DATABASE testtest2 (27)



46.7k

I create a separate PDO object for that and I use the same Phalcon DB config settings except that I don't set the database. Also typically creating a new database is a more admin CLI type of a function and I like to separate that sort of stuff out a bit.