Skip to content

Commit

Permalink
Release for composer v2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Rackham committed Mar 10, 2023
1 parent d5e8c3e commit 8930083
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
19 changes: 15 additions & 4 deletions DBPDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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));
Expand Down
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8930083

Please sign in to comment.