PHP ~ MsSQL DB Class

define('HOSTNAME', 'BITTY-NOTEBOOK\SQLEXPRESS');
define('USERNAME', 'sa'); 
define('PASSWORD', '4785735');
define('DATABASE', 'Gold');  

class DB{
 private $dbLink;
 private $result;
 
 public function __construct()
 {
  $this->connect();
 }
 
 protected function connect()
 {
  $this->dbLink = mssql_connect(HOSTNAME, USERNAME, PASSWORD) or die("Couldn't connect to SQL Server");
  if (!$this->dbLink || !mssql_select_db(DATABASE, $this->dbLink))
  {
   die('Unable to connect or select database!');
  }
 }
 
 public function query($sql)
 {
  $this->result = mssql_query($sql, $this->dbLink);
 }
 
 public function fetch()
 {
  return mssql_fetch_array($this->result);
 }
 
 public function close()
 {
  mssql_close($this->dbLink);
 }
 
}

$db = new DB();
$sql = "INSERT INTO [Gold].[dbo].[Prices] ([Buy] ,[Sell] ,[Time]) VALUES (".$buy." ,".$sell." ,'".$time."')";
$db->query($sql);
$db->close();

沒有留言: