Viewing file: connMySQL.class.php (3.93 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
//--- Main.inc.php
//--- Class DBConn use to connect to MySQL Server
class DBConn {
//### DataBase Variables
var $result;
var $_resource;
var $_numrows;
//### Connect to MIS MySQL Server
function DBConn(){
global $_Config_MISDBHost, $_Config_MISDBUser, $_Config_MISDBPass, $_Config_MISDBName;
//--- perform a number of fatality checks, then die gracefully
if (!function_exists( 'mysql_connect' )) {
die( 'FATAL ERROR: MySQL support not available. Please check your configuration.' );
exit();
}
//if (!($this->_resource = mysql_connect( "localhost", "root", "1234"))) { // local
if (!($this->_resource = mysql_connect($_Config_MISDBHost, $_Config_MISDBUser, $_Config_MISDBPass))) { // Server
die( "FATAL ERROR: Connection to database server failed. $_Config_MISDBHost, $_Config_MISDBUser, $_Config_MISDBPass, $_Config_MISDBName" );
exit();
}
//if (!mysql_select_db("managev3_db")) { // local
if (!mysql_select_db($_Config_MISDBName)) { // Server
die( "FATAL ERROR: Database not found. Operation failed with error: ".mysql_error() );
exit();
}
mysql_query("SET NAMES tis620");
}
//### Connect to REG MySQL Server
function RegDBConn(){
global $_Config_REGDBHost, $_Config_REGDBUser, $_Config_REGDBPass, $_Config_REGDBName;
//--- perform a number of fatality checks, then die gracefully
if (!function_exists( 'mysql_connect' )) {
die( 'FATAL ERROR: MySQL support not available. Please check your configuration.' );
exit();
}
//if (!($this->_resource = mysql_connect( "localhost", "root", "1234"))) { // local
if (!($this->_resource = mysql_connect($_Config_REGDBHost, $_Config_REGDBUser, $_Config_REGDBPass))) { // Server
die( 'FATAL ERROR: Connection to database server failed.' );
exit();
}
//if (!mysql_select_db("managev3_db")) { // local
if (!mysql_select_db($_Config_REGDBName)) { // Server
die( "FATAL ERROR: Database not found. Operation failed with error: ".mysql_error() );
exit();
}
mysql_query("SET NAMES tis620");
}
//### Disconnect
function disconn() {
$ret = mysql_close($this->_resource);
$this->_resource = null;
return $ret;
}
//### Query user this function for run query and return number of rows too : for SELECT query
function execQuery($sql) {
$cur = mysql_query($sql);
//--- handle error
if(!$cur) {
$this->DisplayErrMsg("Error in query : $sql. ". mysql_error());
exit;
}
$this->_numrows = mysql_num_rows($cur);
return($cur);
}
//### Query user this function for run query only : for INSERT, DELETE, UPDATE query
function runQuery($sql) {
$cur = mysql_query($sql);
// handle error
if(!$cur){
$this->DisplayErrMsg("Error in query : $sql. ". mysql_error());
exit;
}
return($cur);
}
//### Fetch Array
function fetchArray($rs) {
$row = mysql_fetch_array($rs);
return($row);
}
//### Fetch Object
function fetchObject($rs) {
$row = mysql_fetch_object($rs);
return($row);
}
//### Free Result
function freeresult($result) {
if (is_resource($result)) {
return mysql_free_result($result);
}
}
//### Display error messages
function DisplayErrMsg( $message ) {
printf("<font color=\"red\">%s</font>\n", $message);
}
//### Insert In (Last Id)
function lastId() {
return mysql_insert_id();
}
//### Affected Rows
function affectedrows() {
return mysql_affected_rows();
}
/**
* Get a database escaped string
* @return string
*/
function getEscaped( $text ) {
return mysql_escape_string( $text );
}
/**
* Get a quoted database escaped string
* @return string
*/
function Quote( $text ) {
return '\'' . mysql_escape_string( $text ) . '\'';
}
function insertid() {
return mysql_insert_id();
}
function getVersion() {
return mysql_get_server_info();
}
} # class
?>
|