<?php
/**
* PDO Singleton Connection
*
* @author wils <wils@wilsolutions.com.br>
*
* @since 2009 Aug
*
* @license GNU GENERAL PUBLIC LICENSE
*
* Note: for aditional info please check PDO docummentation at:
* http://ca.php.net/manual/en/book.pdo.php
*
* @version 1.1
*
*/
class DBConnect
{
private $dsn = 'mysql:dbname=ibanx;host=127.0.0.1';
private $user = 'root';
private $pass = '';
private $options = null;
protected static $instance;
/**
* To get/initiate PDO instance
*
* @return PDO resource
*/
protected function __construct()
{
if(!isset(self::$instance))
{
try
{
self::$instance = new PDO($this->dsn, $this->user, $this->pass, $this->options);
}
catch(PDOException $e)
{
echo 'Connection failed: ' . $this->e->getMessage();
}
}
return self::$instance;
}
/**
* To avoid copies
*/
protected function __clone(){}
public function beginTransaction()
{
return self::$instance->beginTransaction();
}
public function commit()
{
return self::$instance->commit();
}
public function exec($query)
{
return self::$instance->exec($query);
}
public function rollBack()
{
return self::$instance->rollBack();
}
public function query($query)
{
return self::$instance->query($query);
}
public function lastInsertId($seqname)
{
return self::$instance->lastInsertId($seqname);
}
}
?>
|