ZendDbSchema
Schema management for Zend Framework
 All Classes Namespaces Functions Pages
Database.php
1 <?php
31 {
39  {
40  $props = array();
41 
42  if ($schema->collate) {
43  $props[] = "COLLATE " . $schema->collate;
44  }
45  if ($schema->getCharset()) {
46  $props[] = "DEFAULT CHARACTER SET " . $schema->getCharset();
47  }
48 
49  $name = $schema->getName();
50 
51  $query = array();
52  $query[] = "DROP DATABASE IF EXISTS `{$name}`";
53  $query[] = "CREATE DATABASE `{$name}` " . join(' ', $props);
54 
55  return join(';' . PHP_EOL, $query);
56  }
57 
65  {
66  if (!$schema->isExist()) {
67  return null;
68  }
69 
70  $props = array();
71  if ($schema->isDirty('collate')) {
72  $props[] = "COLLATE " . $schema->collate;
73  }
74  if ($schema->getCharset()) {
75  $props[] = "DEFAULT CHARACTER SET " . $schema->getCharset();
76  }
77 
78  $query = '';
79  if (!empty($props)) {
80  $name = $schema->getName();
81  $query = "ALTER DATABASE `{$name}` ". join(' ', $props);
82  }
83  return $query;
84  }
85 
93  {
94  if (!$schema->isExist()) {
95  return null;
96  }
97  return "DROP DATABASE IF EXISTS {$schema->getOriginName()}";
98  }
99 }