使用 DB2 pureXML 和 PHP 构建 Support Knowledge Base(上)
2010-02-25 00:00:00 来源:WEB开发网清单 2. db.php
<?php
class DB {
private $conn;
function __construct() {
$database = "kbase";
$hostname = "localhost";
$port = 50000;
$user = "username";
$password = "password";
$db_connect_string = "DRIVER={IBM DB2 ODBC DRIVER};"
. "DATABASE=$database;"
. "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;"
. "UID=$user;PWD=$password;";
$this->conn = db2_connect($db_connect_string, '', '');
if(!$this->conn) {
die(db2_conn_errormsg($this->conn));
}
}
function safe_no_html($string, $include_quotes=true) {
htmlentities($string, ENT_QUOTES, 'utf-8');
if($include_quotes)
return "'".db2_escape_string($string)."'";
else return db2_escape_string($string);
}
function query($sql) {
$result = db2_exec($this->conn, $sql);
if(!$result) {
die(db2_stmt_errormsg());
} else {
return $result;
}
}
function get_row($result) {
return db2_fetch_array($result);
}
}
?>
更多精彩
赞助商链接