|
1 | 1 | <?php |
| 2 | + |
2 | 3 | // include pdo helper class to use common methods |
3 | 4 | require_once '../src/Helper/PDOHelper.php'; |
4 | 5 | // include pdo class wrapper |
5 | 6 | require_once '../src/class.pdowrapper.php'; |
6 | 7 |
|
7 | 8 | // database connection setings |
8 | | -$dbConfig = ["host" => "localhost", "dbname" => 'sampledb', "username" => 'root', "password" => '']; |
| 9 | +$dbConfig = ['host' => 'localhost', 'dbname' => 'sampledb', 'username' => 'root', 'password' => '']; |
9 | 10 | // get instance of PDO Wrapper object |
10 | 11 | $db = new PdoWrapper($dbConfig); |
11 | 12 |
|
|
15 | 16 | // set error log mode true to show error on screen or false to log in log file |
16 | 17 | $db->setErrorLog(true); |
17 | 18 |
|
18 | | - |
19 | 19 | /** |
20 | | - * run simple mysql query |
| 20 | + * run simple mysql query. |
21 | 21 | * |
22 | 22 | * showQuery = display executed query |
23 | 23 | * results = get array results |
|
26 | 26 | // print array result |
27 | 27 | $helper->PA($q); |
28 | 28 |
|
29 | | - |
30 | 29 | /** |
31 | 30 | * run simple mysql query with where clause |
32 | | - * pass where value as an parametrised array |
| 31 | + * pass where value as an parametrised array. |
33 | 32 | * |
34 | 33 | * ? presenting place holder here for where clause values |
35 | 34 | */ |
36 | 35 | $q = $db->pdoQuery('select * from customers where (customernumber = ? OR customernumber = ?) ;', [103, 119])->showQuery()->results(); |
37 | 36 | // print array result |
38 | 37 | $helper->PA($q); |
39 | 38 |
|
40 | | - |
41 | 39 | /** |
42 | | - * run simple mysql query and get third row of array results |
| 40 | + * run simple mysql query and get third row of array results. |
43 | 41 | * |
44 | 42 | * result(2) = will return 3rd row of array data |
45 | 43 | */ |
46 | 44 | $q = $db->pdoQuery('select * from customers;')->showQuery()->result(2); |
47 | 45 | // print array result |
48 | 46 | $helper->PA($q); |
49 | 47 |
|
50 | | - |
51 | 48 | /** |
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. |
53 | 50 | */ |
54 | 51 | $q = $db->pdoQuery('select * from customers where (customernumber = ? OR contactLastName = ?) ;', [112, 'Schmitt'])->showQuery()->results(); |
55 | 52 | // print array result |
56 | 53 | $helper->PA($q); |
57 | 54 |
|
58 | | - |
59 | 55 | /** |
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. |
61 | 57 | */ |
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;'; |
63 | 59 |
|
64 | 60 | $q = $db->pdoQuery($innerJoinSql)->showQuery()->results(); |
65 | 61 | // print array result |
|
0 commit comments