-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp_run_bean.php
146 lines (123 loc) · 4.51 KB
/
app_run_bean.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* Demo usage of the generated class by mysqlreflection tools
* Generated bean used: BeanSinglePkDate
*
*/
error_reporting(E_ALL);
header('Content-Type: text/html; charset=utf-8');
include_once("beans/bean.config.php");
include_once("beans/BeanSinglePkDate.php");
// INSERT a new row and show result
$bean = new BeanSinglePkDate();
$bean->setIdDate("10/10/1950");
$bean->setFieldDate("10/10/1951");
$bean->setFieldDateTime("10/10/1952 10:11:12");
$bean->setFieldInt(100);
$bean->setFieldDecimal(100.35);
$bean->setFieldString('STRING with apho\'s and accènt');
$bean->setFieldText("TEXT with apho's and accènt");
$result = $bean->insert();
$lastInserted = $bean->getIdDate();
showBeanOperationResult("INSERT",$bean,$bean->affected_rows,false);
echo $lastInserted . " last inserted<br/>";
$bean->close();
// SELECT previously inserted row and show result
$bean = new BeanSinglePkDate($lastInserted);
showBeanOperationResult("SELECT",$bean,$bean->affected_rows);
$bean->close();
// UPDATE previously inserted row and show result
$bean = new BeanSinglePkDate($lastInserted);
$bean->setFieldDate("10/10/1952");
$bean->setFieldDecimal(200.45);
$bean->setFieldInt(200);
$bean->setFieldString("This is a new STRING with apho's and accènt");
$bean->setFieldText("This is a new TEXT with apho's and accènt");
$result = $bean->updateCurrent();
showBeanOperationResult("UPDATE",$bean,$result,true);
$bean->close();
// DELETE previously updated row and show result
$bean = new BeanSinglePkDate($lastInserted);
$result = $bean->delete($lastInserted);
showBeanOperationResult("DELETE",$bean,$result);
$bean->close();
// Select after deletion and show result
$bean = new BeanSinglePkDate($lastInserted);
showBeanOperationResult("SELECT AFTER DELETION",$bean,$bean->affected_rows);
$bean->close();
/**
* Support functions to show result
*/
/**
* Show Sale bean information and the MySQLi result for the current object operation
* @param string $operation the class operation
* @param mixed $bean current object
* @param mysqli $result the mysql result for the operation
* @param bool $ddl if true show the DDL
*/
function showBeanOperationResult($operation, BeanSinglePkDate $bean,$result,$ddl = false)
{
echo "<br/><b>BEGIN</b> application operation: <b>$operation</b><br/>";
showBean($bean,$operation,$ddl);
showMySqlResult($result);
echo "<b>END</b> application operation: <b>$operation</b><br/><br/><br/>";
}
/**
* Shows some information about current sales agent object
* @param mixed $bean
* @param string $operation the class operation
* @param bool $showDdl
*/
function showBean(BeanSinglePkDate $bean = null, $operation, $showDdl = false)
{
// If no errors
if ($bean && !$bean->isSqlError()) {
echo "<br/>";
echo "<b>Bean information:</b>:<hr>";
echo "field_id : {$bean->getIdDate()}<br/>";
echo "field_date : {$bean->getFieldDate()}<br/>";
echo "field_date_time : {$bean->getFieldDateTime()}<br/>";
echo "field_int : {$bean->getFieldInt()}<br/>";
echo "field_decimal : {$bean->getFieldDecimal()}<br/>";
echo "field_string : {$bean->getFieldString()}<br/>";
echo "field_text : {$bean->getFieldText()}<br/>";
echo "<br/>";
// Shows sql statements
echo "<div style='background: lightgrey'>";
echo "<sup>Executed SQL statemtent:</sup><br/>";
echo $bean->lastSql() . "<br/>";
echo "</div>";
}
// If errors
if ($bean && $bean->isSqlError()) {
echo "<br/>";
echo "<b>Error Unable to show bean object information:</b>";
echo "<hr>";
echo "<div style='background:indianred'>";
echo "Error:" . $bean->lastSqlError();
echo "<br/>";
echo $bean->lastSql();
echo "</div>";
}
// If DDL info requested and no error
if ($bean && $showDdl){
echo "<br/>";
echo "<br/><sup>You requested to see DDL information:</sup><br/>";
echo "<div style='background: yellowgreen'>";
echo "<pre>";
echo $bean->getDdl();
echo "</pre>";
echo "</div>";
}
}
/**
* Show MySql Result
* @param mixed MySql $result
*/
function showMySqlResult($result){
echo "<br/>";
echo "<div style='background: lightcyan'>";
echo "<sup>MySQL result for operation:</sup>";
var_dump($result);
echo "</div>";
}