| | 97 | /** |
|---|
| | 98 | * |
|---|
| | 99 | * Creates a PDO-style DSN. |
|---|
| | 100 | * |
|---|
| | 101 | * For example, "mysql:host=127.0.0.1;dbname=test" |
|---|
| | 102 | * |
|---|
| | 103 | * @return string A PDO-style DSN. |
|---|
| | 104 | * |
|---|
| | 105 | */ |
|---|
| | 106 | protected function _dsn() |
|---|
| | 107 | { |
|---|
| | 108 | $dsn = array(); |
|---|
| | 109 | |
|---|
| | 110 | // socket, or host-and-port? (can't use both.) |
|---|
| | 111 | if (! empty($this->_config['sock'])) { |
|---|
| | 112 | |
|---|
| | 113 | // use a socket |
|---|
| | 114 | $dsn[] = 'unix_socket=' . $this->_config['sock']; |
|---|
| | 115 | |
|---|
| | 116 | } else { |
|---|
| | 117 | |
|---|
| | 118 | // use host and port |
|---|
| | 119 | if (! empty($this->_config['host'])) { |
|---|
| | 120 | $dsn[] = 'host=' . $this->_config['host']; |
|---|
| | 121 | } |
|---|
| | 122 | |
|---|
| | 123 | if (! empty($this->_config['port'])) { |
|---|
| | 124 | $dsn[] = 'port=' . $this->_config['port']; |
|---|
| | 125 | } |
|---|
| | 126 | |
|---|
| | 127 | } |
|---|
| | 128 | |
|---|
| | 129 | // database name |
|---|
| | 130 | if (! empty($this->_config['name'])) { |
|---|
| | 131 | $dsn[] = 'dbname=' . $this->_config['name']; |
|---|
| | 132 | } |
|---|
| | 133 | |
|---|
| | 134 | return $this->_pdo_type . ':' . implode(';', $dsn); |
|---|
| | 135 | } |
|---|
| | 136 | |
|---|
| | 137 | |
|---|
| | 138 | |
|---|