Skip to content

Commit

Permalink
#1052: 작업 중...
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Jul 20, 2008
1 parent 67b40bd commit 549bccd
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 20 deletions.
50 changes: 30 additions & 20 deletions framework/data/mysql/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)

// TODO: process errors and exceptions

class Adapter implements IAdapter
class MySQLAdapter implements IAdapter
{
function __construct()
{
Expand All @@ -19,54 +17,66 @@ function __destruct()

public function connect($server, $dbname, $userid, $password, array $options)
{
if ($options != NULL) {
foreach ($options as $key => $value) {
switch ($key) {
default:
// Do something with options
break;
}
}
}
$this->conn = mysql_connect($server, $userid, $password);
if ($this->conn === false)
throw new ConnectionError();
@mysql_query("SET NAMES UTF8");
@mysql_query("SET CHARACTER SET UTF8");
mysql_query("USE $dbname");
if ($this->conn === FALSE) {
$this->conn = NULL;
throw new ConnectionError(mysql_error());
}
@mysql_query("SET NAMES UTF8", $this->conn);
@mysql_query("SET CHARACTER SET UTF8", $this->conn);
if (mysql_select_db($dbname, $this->conn) === FALSE)
throw new DBError("No such database: $dbname");
}

public function disconnect()
{
if ($this->conn)
if ($this->conn) {
mysql_close($this->conn);
$this->conn = NULL;
}
}

public function beginTransaction()
{
mysql_query("BEGIN");
mysql_query("BEGIN", $this->conn);
}

public function endTransaction($apply = true)
public function endTransaction($apply = TRUE)
{
if ($apply)
mysql_query("COMMIT");
mysql_query("COMMIT", $this->conn);
else
mysql_query("ROLLBACK");
mysql_query("ROLLBACK", $this->conn);
}

public function query($query)
{
return mysql_query($query);
return mysql_query($query, $this->conn);
}

public static function escapeString($var)
{
if (is_array($var)) {
if (is_array($var))
return array_map(escapeString, $var);
} else {
else
return mysql_escape_string($var);
}
}

public static function escapeFieldName($var)
{
if (is_array($var)) {
if (is_array($var))
return array_map(escapeFieldName, $var);
} else {
else
return '`'.$var.'`';
}
}
}
?>
75 changes: 75 additions & 0 deletions framework/data/postgresql/Adapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/// Copyright (c) 2004-2008, Needlworks / Tatter Network Foundation
/// All rights reserved. Licensed under the GPL.
/// See the GNU General Public License for more details. (/doc/LICENSE, /doc/COPYRIGHT)

class PSQLAdapter implements IAdapter
{
function __construct()
{
$this->conn = NULL;
}

function __destruct()
{
$this->disconnect();
}

public function connect($server, $dbname, $userid, $password, array $options)
{
$connection_str = "host=$server dbname=$dbname user=$userid password=$password";
if ($options != NULL) {
foreach ($options as $key => $value) {
switch ($key) {
default:
// Do something with options
break;
}
}
}
$this->conn = pg_connect($connection_str);
if (pg_connection_status($this->conn) === PSQL_CONNECTION_OK) {
pg_set_client_encoding($this->conn, 'UTF8');
} else {
$this->conn = NULL;
throw new ConnectionError(pg_last_error());
}
}

public function disconnect()
{
if ($this->conn) {
pg_close($this->conn);
$this->conn = NULL;
}
}

public function beginTransaction()
{
pg_query($this->conn, "BEGIN");
}

public function endTransaction($apply = TRUE)
{
if ($apply)
pg_query($this->conn, "COMMIT");
else
pg_query($this->conn, "ROLLBACK");
}

public static function escapeString($var)
{
if (is_array($var))
return array_map(escapeString, $var);
else
return pg_escape_string($var);
}

public static function escapeFieldName($var)
{
// TODO: how to do this in psql?
return $var;
}
}

?>

0 comments on commit 549bccd

Please sign in to comment.