-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_simple.php
88 lines (58 loc) · 2.65 KB
/
example_simple.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php /** @noinspection PhpUnhandledExceptionInspection */
use dBug\dBug;
use eftec\PdoOne;
use mapache_commons\Collection;
include __DIR__.'/common.php';
$pdoOne->truncate('customers','',true);
$pdoOne->resetIdentity('customers');
$pdoOne->truncate('invoices','',true);
$pdoOne->resetIdentity('invoices');
$pdoOne->truncate('invoice_details','',true);
$pdoOne->resetIdentity('invoice_details');
// Creating a new customer********************************
// raw query.
$statement=$pdoOne->runRawQuery('insert into customers(name) values (?)',['John Simple'],false);
$statement->closeCursor(); // it is a pdostatement
$statement=null;
$idCustomer=$pdoOne->insert_id();
$firstCustomer=$idCustomer;
echo "added user $idCustomer<br>";
// raw query.
$pdoOne->runRawQuery('insert into customers(name) values (?)',['John Simple'],true);
$idCustomer=$pdoOne->insert_id();
echo "added user $idCustomer<br>";
// named raw query
$pdoOne->runRawQuery('insert into customers(name) values (:name)',['name'=>'John Simple'],true);
$idCustomer=$pdoOne->insert_id();
echo "added user $idCustomer<br>";
// *************** list ***********************
// list raw query
$customers=$pdoOne->runRawQuery('select * from customers where name=?',['John Simple']);
echo Collection::generateTable($customers);
// **************** one value **************************************
// raw query
$customer=$pdoOne->runRawQuery('select * from customers where idcustomer=?',[$firstCustomer]);
echo "<pre>";
var_dump($customer[0]);
echo "</pre>";
// Creating an invoice
// -------------------------------------------
$invoice=['IdInvoice'=>1,'Date'=> PdoOne::dateSqlNow(true), 'IdCustomer'=>1];
$pdoOne->runRawQuery('insert into invoices(idinvoice,date,idcustomer) values(:IdInvoice,:Date,:IdCustomer)',$invoice);
// Creating the detail of the invoice
$invoiceDetail=[1,'Cocacola',1000,3];
$query='insert into invoice_details(idinvoice,product,unitprice,quantity) values (?,?,?,?)';
$pdoOne->runRawQuery($query, $invoiceDetail);
$invoiceDetail=[1,'Fanta',2000,5];
$query='insert into invoice_details(idinvoice,product,unitprice,quantity) values (?,?,?,?)';
$pdoOne->runRawQuery($query, $invoiceDetail);
// *********** listing invoice
$invoices=$pdoOne->runRawQuery('select * from invoices');
echo Collection::generateTable($invoices);
// *********** listing invoicedetails
$invoiceDetails=$pdoOne->runRawQuery('select * from invoice_details');
echo Collection::generateTable($invoiceDetails);
// getting all together.
$invoice=$pdoOne->runRawQuery('select * from invoices where idinvoice=?',[1]);
$invoice[0]['details']=$pdoOne->runRawQuery('select * from invoice_details where idinvoice=?',[1]);
new dBug($invoice[0]);