diff --git a/DBPDO.php b/DBPDO.php index 35d179c..990be3e 100644 --- a/DBPDO.php +++ b/DBPDO.php @@ -2,13 +2,24 @@ namespace A1phanumeric; +use \PDO; +use \PDOException; + class DBPDO { public $pdo; private $error; + private $dbname; + private $dbhost; + private $dbuser; + private $dbpass; - function __construct() { + function __construct($dbhost = '', $dbname = '', $dbuser = '', $dbpass= '') { + $this->dbhost = $dbhost; + $this->dbname = $dbname; + $this->dbuser = $dbuser; + $this->dbpass = $dbpass; $this->connect(); } @@ -21,9 +32,9 @@ function prep_query($query){ function connect(){ if(!$this->pdo){ - $dsn = 'mysql:dbname=' . DATABASE_NAME . ';host=' . DATABASE_HOST.';charset=utf8'; - $user = DATABASE_USER; - $password = DATABASE_PASS; + $dsn = 'mysql:dbname=' . $this->dbname . ';host=' . $this->dbhost . ';charset=utf8'; + $user = $this->dbuser; + $password = $this->dbpass; try { $this->pdo = new PDO($dsn, $user, $password, array(PDO::ATTR_PERSISTENT => true)); diff --git a/readme.md b/readme.md index b61ad31..8bd7fb2 100644 --- a/readme.md +++ b/readme.md @@ -12,8 +12,20 @@ PHP MySQL Class This is a simple to use MySQL class that easily bolts on to any existing PHP application, streamlining your MySQL interactions. +Setup v2.0+ +----- + +Include the class using composer as below: + +`composer require a1phanumeric/php-mysql-class` + +To use in your project, use the following: + +`use A1phanumeric\DBPDO;` + +`$DB = new DBPDO('db_name', 'db_host', 'db_user', 'db_pass');` -Setup +###Setup Before v2.0 ----- Firstly, define four constants for the host, database name, username and password: