File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 22
33namespace A1phanumeric ;
44
5+ use \PDO ;
6+ use \PDOException ;
7+
58class 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 ));
Original file line number Diff line number Diff line change @@ -12,8 +12,20 @@ PHP MySQL Class
1212
1313This 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
1931Firstly, define four constants for the host, database name, username and password:
You can’t perform that action at this time.
0 commit comments