Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8930083

Browse files
author
Ed Rackham
committed
Release for composer v2.0
1 parent d5e8c3e commit 8930083

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

‎DBPDO.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,24 @@
22

33
namespace A1phanumeric;
44

5+
use \PDO;
6+
use \PDOException;
7+
58
class DBPDO {
69

710
public $pdo;
811
private $error;
12+
private $dbname;
13+
private $dbhost;
14+
private $dbuser;
15+
private $dbpass;
916

1017

11-
function __construct() {
18+
function __construct($dbhost = '', $dbname = '', $dbuser = '', $dbpass= '') {
19+
$this->dbhost = $dbhost;
20+
$this->dbname = $dbname;
21+
$this->dbuser = $dbuser;
22+
$this->dbpass = $dbpass;
1223
$this->connect();
1324
}
1425

@@ -21,9 +32,9 @@ function prep_query($query){
2132
function connect(){
2233
if(!$this->pdo){
2334

24-
$dsn = 'mysql:dbname=' . DATABASE_NAME . ';host=' . DATABASE_HOST.';charset=utf8';
25-
$user = DATABASE_USER;
26-
$password = DATABASE_PASS;
35+
$dsn = 'mysql:dbname=' . $this->dbname . ';host=' . $this->dbhost . ';charset=utf8';
36+
$user = $this->dbuser;
37+
$password = $this->dbpass;
2738

2839
try {
2940
$this->pdo = new PDO($dsn, $user, $password, array(PDO::ATTR_PERSISTENT => true));

‎readme.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ PHP MySQL Class
1212

1313
This is a simple to use MySQL class that easily bolts on to any existing PHP application, streamlining your MySQL interactions.
1414

15+
Setup v2.0+
16+
-----
17+
18+
Include the class using composer as below:
19+
20+
`composer require a1phanumeric/php-mysql-class`
21+
22+
To use in your project, use the following:
23+
24+
`use A1phanumeric\DBPDO;`
25+
26+
`$DB = new DBPDO('db_name', 'db_host', 'db_user', 'db_pass');`
1527

16-
Setup
28+
###Setup Before v2.0
1729
-----
1830

1931
Firstly, define four constants for the host, database name, username and password:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /