Skip to content

Instantly share code, notes, and snippets.

@koshiaaaaan
Created December 23, 2010 02:25
Show Gist options
  • Save koshiaaaaan/752467 to your computer and use it in GitHub Desktop.
Save koshiaaaaan/752467 to your computer and use it in GitHub Desktop.
複数コネクションを持つ場合。こんな感じかなぁ・・・
<?php
class DB{
var $db_encoding="UTF-8";
var $script_encoding="UTF-8";
var $db=null;
#---------------------------
# constructer
#---------------------------
function DB($db=DBNAME,$user=USER,$pass=PASS,$host=HOST){
# CONNECT MySQL
if (!($mysql=mysql_connect($host,$user,$pass,true))) {
die("ERROR: HOST CONNECT FAILED");
}
$this->db = $mysql ;
# CONNECT DB
if (!(mysql_select_db($db,$this->db))) {
die("ERROR: DB CONNECT FAILED");
}
}
#---------------------------
# class method
#---------------------------
function exe($stmt){
# Execute SQL
if (!($data = mysql_query($stmt,$this->db))) {
echo mysql_error($this->db)."\n";
var_dump($stmt);
return false;
}
$result = Array();
while($tmp = @mysql_fetch_assoc($data)){
array_push($result,$tmp);
}
if( !empty ( $result ) ){
return $result;
}else{
return TRUE;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment