forked from pyrus/pearhunt
/
Database.php
51 lines (48 loc) · 1.23 KB
/
Database.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Simple Active Record implementation for pearhunt
*
* PHP version 5
*
* @category Utilities
* @package pearhunt
* @author Till Klampaeckel <till@php.net>
* @copyright 2011 Till Klampaeckel
* @license http://www1.unl.edu/wdn/wiki/Software_License BSD License
* @link http://pear2.php.net/
*/
/**
* Simple active record implementation for pearhunt.
*
* PHP version 5
*
* @category Utilities
* @package pearhunt
* @author Till Klampaeckel <till@php.net>
* @copyright 2011 Till Klampaeckel
* @license http://www1.unl.edu/wdn/wiki/Software_License BSD License
* @link http://pear2.php.net/
*/
class Database
{
/**
* Create the database.
*
* @return void
* @throws RuntimeException When it didn't work.
*
* @uses Config::getDbSettings()
* @uses Record::getDb()
*/
public static function create()
{
$settings = Config::getDbSettings();
$db = Record::getDb(false);
$dbName = $db->real_escape_string($settings['dbname']);
$sql = "CREATE DATABASE IF NOT EXISTS $dbName";
if ($db->query($sql) === true) {
return;
}
throw new RuntimeException($db->error, $db->errno);
}
}