-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_mysql.php
99 lines (65 loc) · 1.61 KB
/
example_mysql.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'vendor/autoload.php';
define('DB_TYPE', 'mysql');
define('DB_HOST', 'localhost');
define('DB_NAME', 'zf1app_db');
define('DB_USER', 'root');
define('DB_PASS', '');
/* //use 1
use Stnc\Db\MysqlAdapter ;
$db = new MysqlAdapter();
*/
/* //use 2
use Stnc\Db\MysqlAdapter as dbs;
$db = new dbs();
*/
//use 3
$db = new stnc\db\MysqlAdapter();
$tableName = 'users';
// multiple rows
$q = "SELECT * FROM ".$tableName;
$array_expression = $db->fetchAll ( $q );
foreach ( $array_expression as $value ) {
echo $value ['username'];
echo '<br>';
}
// single row
$q = "SELECT * FROM ".$tableName ." where id=1";
$array_expression = $db->fetch ( $q );
echo $value ['username'];
//print_r($array_expression);
// query metod mysq only
$q = "ALTER TABLE users MODIFY COLUMN id int(11) NOT NULL AUTO_INCREMENT FIRST";
$db->query ( $q );
// insert data
$data = array (
'first_name' => "john",
'last_name' => "carter",
'username' => "rob",
'password' => "12345",
);
//print_r($data );
$db->insert ( $tableName, $data );
// update metod
$data = array (
'first_name' => "johnx",
'last_name' => "carter",
);
$where = array (
'id' => 1
);
$db-> update ( $tableName, $data, $where );
$where = array (
'id' => 5
);
$db->delete ( $tableName, $where );
//last id
$db->lastID();
///NEW MTEOD //Chaining methods where update //orm step 2
$db->where('id', '=', 1)->update2(['username' =>'selman sedat']);
//orm step 1
$db->tableName=$tableName;
$array_expression = $db->where_test ( 'id','=','1' );