ZendDbSchema
Schema management for Zend Framework
 All Classes Namespaces Functions Pages
Database.php
1 <?php
31 {
39  {
40  $props = array();
41 
42  if ($schema->owner) {
43  $props[] = "OWNER {$schema->owner}";
44  }
45  if ($schema->getCharset()) {
46  $props[] = "ENCODING " . $schema->getCharset();
47  }
48 
49  if ($schema->template) {
50  $props[] = "TEMPLATE {$schema->template}";
51  }
52 
53  if ($schema->tablespace) {
54  $props[] = "TABLESPACE {$schema->tablespace}";
55  }
56 
57  if ($schema->connlimit) {
58  $props[] = "CONNECTION LIMIT {$schema->connlimit}";
59  }
60 
61  $name = $schema->getName();
62  $query = array();
63  $query[] = "DROP DATABASE IF EXISTS {$name}";
64  $query[] = "CREATE DATABASE {$name} " . join(' ', $props);
65 
66  return join(';' . PHP_EOL, $query);
67  }
68 
76  {
77  if (!$schema->isExist()) {
78  return null;
79  }
80 
81  $props = array();
82  if ($schema->template) {
83  $props[] = "ENCODING {$schema->template}";
84  }
85 
86  if ($schema->tablespace) {
87  $props[] = "TABLESPACE {$schema->tablespace}";
88  }
89 
90  if ($schema->connlimit) {
91  $props[] = "CONNECTION LIMIT {$schema->connlimit}";
92  }
93 
94  $name = $schema->getName();
95 
96  $query = '';
97  if ($schema->isDirty('charset')) {
98  $charset = $schema->getCharset();
99  $query = "ALTER DATABASE {$name} DEFAULT CHARACTER SET {$charset}";
100  }
101  return $query;
102  }
103 
111  {
112  if (!$schema->isExist()) {
113  return null;
114  }
115  return "DROP DATABASE IF EXISTS {$schema->getOriginName()}";
116  }
117 }