Skip to content

Commit 3844414

Browse files
authored
Merge pull request #9 from dframe/psr2
PSR2, Clean Code
2 parents 643d835 + 2ea4407 commit 3844414

16 files changed

Lines changed: 239 additions & 225 deletions

example/delete_demo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
// include pdo helper class to use common methods
34
require_once '../src/Helper/PDOHelper.php';
45
// include pdo class wrapper
56
require_once '../src/class.pdowrapper.php';
67

78
// database connection setings
8-
$dbConfig = ["host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => ''];
9+
$dbConfig = ['host' => 'localhost', 'dbname' => 'sampledb', 'username' => 'root', 'password' => ''];
910
// get instance of PDO Wrapper object
1011
$db = new PdoWrapper($dbConfig);
1112

@@ -24,7 +25,6 @@
2425
// print affected rows
2526
PDOHelper::PA($q);
2627

27-
2828
// Example -2
2929

3030
// where condition array

example/insert_demo.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
//300 seconds = 5 minutes execution time
34
ini_set('max_execution_time', 300);
45
// overrides the default PHP memory limit.
@@ -10,7 +11,7 @@
1011
require_once '../src/class.pdowrapper.php';
1112

1213
// database connection setings
13-
$dbConfig = ["host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => ''];
14+
$dbConfig = ['host' => 'localhost', 'dbname' => 'sampledb', 'username' => 'root', 'password' => ''];
1415
// get instance of PDO Wrapper object
1516
$db = new PdoWrapper($dbConfig);
1617

@@ -26,28 +27,24 @@
2627
$q = $db->insert('test', $dataArray)->showQuery()->getLastInsertId();
2728
PDOHelper::PA($q);
2829

29-
3030
// Example -2
3131
$dataArray = ['first_name' => 'Scott', 'last_name' => 'Dimon', 'age' => 55];
3232
// use insert function
3333
$q = $db->insert('test', $dataArray)->showQuery()->getLastInsertId();
3434
PDOHelper::PA($q);
3535

36-
3736
// Example -3
3837
$dataArray = ['first_name' => 'Simran', 'last_name' => 'Singh', 'age' => 25];
3938
// use insert function
4039
$q = $db->insert('testt', $dataArray)->showQuery()->getLastInsertId();
4140
PDOHelper::PA($q);
4241

43-
4442
// Example -4
4543
// use insert function
4644
$q = $db->insert('test', $dataArray)->showQuery()->getLastInsertId();
4745
// print array last insert id
4846
PDOHelper::PA($q);
4947

50-
5148
// Example -5 (Bulk Insert)
5249
// loop start to create insert data
5350
$dataArray = [];

example/query_demo.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
// include pdo helper class to use common methods
34
require_once '../src/Helper/PDOHelper.php';
45
// include pdo class wrapper
56
require_once '../src/class.pdowrapper.php';
67

78
// database connection setings
8-
$dbConfig = ["host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => ''];
9+
$dbConfig = ['host' => 'localhost', 'dbname' => 'sampledb', 'username' => 'root', 'password' => ''];
910
// get instance of PDO Wrapper object
1011
$db = new PdoWrapper($dbConfig);
1112

@@ -15,9 +16,8 @@
1516
// set error log mode true to show error on screen or false to log in log file
1617
$db->setErrorLog(true);
1718

18-
1919
/**
20-
* run simple mysql query
20+
* run simple mysql query.
2121
*
2222
* showQuery = display executed query
2323
* results = get array results
@@ -26,40 +26,36 @@
2626
// print array result
2727
$helper->PA($q);
2828

29-
3029
/**
3130
* run simple mysql query with where clause
32-
* pass where value as an parametrised array
31+
* pass where value as an parametrised array.
3332
*
3433
* ? presenting place holder here for where clause values
3534
*/
3635
$q = $db->pdoQuery('select * from customers where (customernumber = ? OR customernumber = ?) ;', [103, 119])->showQuery()->results();
3736
// print array result
3837
$helper->PA($q);
3938

40-
4139
/**
42-
* run simple mysql query and get third row of array results
40+
* run simple mysql query and get third row of array results.
4341
*
4442
* result(2) = will return 3rd row of array data
4543
*/
4644
$q = $db->pdoQuery('select * from customers;')->showQuery()->result(2);
4745
// print array result
4846
$helper->PA($q);
4947

50-
5148
/**
52-
* run mysql select query with where clause and or using parametrise array param
49+
* run mysql select query with where clause and or using parametrise array param.
5350
*/
5451
$q = $db->pdoQuery('select * from customers where (customernumber = ? OR contactLastName = ?) ;', [112, 'Schmitt'])->showQuery()->results();
5552
// print array result
5653
$helper->PA($q);
5754

58-
5955
/**
60-
* run mysql select query with where clause and or using parametrise array param
56+
* run mysql select query with where clause and or using parametrise array param.
6157
*/
62-
$innerJoinSql = "select p.checknumber, p.amount, p.paymentdate, c.customernumber, c.customerName, c.contactLastName, c.contactFirstName, c.phone, c.addressLine1, c.addressLine2, c.city, c.state, c.postalCode, c.country from payments as p inner join customers as c on p.customernumber = c.customernumber order by p.amount desc limit 2;";
58+
$innerJoinSql = 'select p.checknumber, p.amount, p.paymentdate, c.customernumber, c.customerName, c.contactLastName, c.contactFirstName, c.phone, c.addressLine1, c.addressLine2, c.city, c.state, c.postalCode, c.country from payments as p inner join customers as c on p.customernumber = c.customernumber order by p.amount desc limit 2;';
6359

6460
$q = $db->pdoQuery($innerJoinSql)->showQuery()->results();
6561
// print array result

example/result_demo.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
// include pdo helper class to use common methods
34
require_once '../src/Helper/PDOHelper.php';
45
// include pdo class wrapper
56
require_once '../src/class.pdowrapper.php';
67

78
// database connection setings
8-
$dbConfig = ["host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => ''];
9+
$dbConfig = ['host' => 'localhost', 'dbname' => 'sampledb', 'username' => 'root', 'password' => ''];
910
// get instance of PDO Wrapper object
1011
$db = new PdoWrapper($dbConfig);
1112

example/select_demo.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
// include pdo helper class to use common methods
34
require_once '../src/Helper/PDOHelper.php';
45
// include pdo class wrapper
56
require_once '../src/class.pdowrapper.php';
67

78
// database connection setings
8-
$dbConfig = ["host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => ''];
9+
$dbConfig = ['host' => 'localhost', 'dbname' => 'sampledb', 'username' => 'root', 'password' => ''];
910
// get instance of PDO Wrapper object
1011
$db = new PdoWrapper($dbConfig);
1112

@@ -15,7 +16,6 @@
1516
// set error log mode true to show error on screen or false to log in log file
1617
$db->setErrorLog(true);
1718

18-
1919
// Example -1
2020
$selectFields = ['customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone'];
2121
// set where condition
@@ -31,15 +31,13 @@
3131
// print array result
3232
PDOHelper::PA($q);
3333

34-
3534
// Example -3
3635
$whereConditions = ['lastname =' => 'bow', 'or jobtitle =' => 'Sales Rep', 'and isactive =' => 1, 'and officecode =' => 1];
3736
// select with where and bind param use select method
3837
$q = $db->select('employees', ['employeeNumber', 'lastName', 'firstName'], $whereConditions)->showQuery()->results();
3938
// print array result
4039
PDOHelper::PA($q);
4140

42-
4341
// Example -4
4442
$selectFields = ['customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone'];
4543
// set where condition
@@ -50,14 +48,13 @@
5048
'and age =' => 30,
5149
'or contactLastName =' => 'Schmitt',
5250
'and age <' => 45,
53-
'or age >' => 65
51+
'or age >' => 65,
5452
];
5553
// select with where and bind param use select method
5654
$q = $db->select('customers', $selectFields, $array_data);
5755
// print array result
5856
PDOHelper::PA($q);
5957

60-
6158
// Example -5
6259
$selectFields = ['customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone'];
6360
// set where condition
@@ -67,7 +64,6 @@
6764
// print array result
6865
PDOHelper::PA($q);
6966

70-
7167
// Example -6
7268
$selectFields = ['customerNumber', 'customerName', 'contactLastName', 'contactFirstName', 'phone'];
7369
// set where condition

example/update_demo.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
23
// include pdo helper class to use common methods
34
require_once '../src/Helper/PDOHelper.php';
45
// include pdo class wrapper
56
require_once '../src/class.pdowrapper.php';
67

78
// database connection setings
8-
$dbConfig = ["host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => ''];
9+
$dbConfig = ['host' => 'localhost', 'dbname' => 'sampledb', 'username' => 'root', 'password' => ''];
910
// get instance of PDO Wrapper object
1011
$db = new PdoWrapper($dbConfig);
1112

@@ -26,9 +27,6 @@
2627
// print affected rows
2728
PDOHelper::PA($q);
2829

29-
30-
31-
3230
// Example -2
3331

3432
// update array data

0 commit comments

Comments
 (0)