File tree 2 files changed +28
-5
lines changed
2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace A1phanumeric ;
4
4
5
+ use \PDO ;
6
+ use \PDOException ;
7
+
5
8
class DBPDO {
6
9
7
10
public $ pdo ;
8
11
private $ error ;
12
+ private $ dbname ;
13
+ private $ dbhost ;
14
+ private $ dbuser ;
15
+ private $ dbpass ;
9
16
10
17
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 ;
12
23
$ this ->connect ();
13
24
}
14
25
@@ -21,9 +32,9 @@ function prep_query($query){
21
32
function connect (){
22
33
if (!$ this ->pdo ){
23
34
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 ;
27
38
28
39
try {
29
40
$ this ->pdo = new PDO ($ dsn , $ user , $ password , array (PDO ::ATTR_PERSISTENT => true ));
Original file line number Diff line number Diff line change @@ -12,8 +12,20 @@ PHP MySQL Class
12
12
13
13
This is a simple to use MySQL class that easily bolts on to any existing PHP application, streamlining your MySQL interactions.
14
14
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'); `
15
27
16
- Setup
28
+ ### Setup Before v2.0
17
29
-----
18
30
19
31
Firstly, define four constants for the host, database name, username and password:
You can’t perform that action at this time.
0 commit comments