Skip to content

Commit f0d1bdd

Browse files
Add files via upload
1 parent 2d0c0e4 commit f0d1bdd

1 file changed

Lines changed: 144 additions & 0 deletions

File tree

dist/mysql.php

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
namespace codeboxsql;
4+
5+
use codeboxsql\connection;
6+
7+
class mysql
8+
{
9+
10+
protected $dbObjectect;
11+
12+
public function __construct($host, $user, $pass, $database)
13+
{
14+
$this->dbObjectect = new connection($host, $user, $pass, $database);
15+
}
16+
17+
18+
function insertInto($tableName, $data)
19+
{
20+
$columns = array_keys($data);
21+
$values = array_values($data);
22+
23+
$Istr = "INSERT INTO $tableName (" . implode(',', $columns) . ") VALUES ('" . implode("', '", $values) . "' )";
24+
if ($this->dbObjectect->query_execute($Istr)) {
25+
return 'done';
26+
} else {
27+
return 'failed';
28+
}
29+
}
30+
31+
function lastId()
32+
{
33+
return $this->dbObjectect->query_lastID();
34+
}
35+
36+
function singleSelect($tableName, $data, $method, $data2)
37+
{
38+
$sqlStmt = '';
39+
$sqlStmt2 = '';
40+
$arr = array();
41+
if ($data == '') {
42+
$sqlStmt = '';
43+
} else {
44+
$columns = array_keys($data);
45+
$values = array_values($data);
46+
$clength = count($columns);
47+
for ($x = 0; $x < $clength; $x++) {
48+
$sqlStmt .= $columns[$x] . " = '" . $values[$x] . "' and ";
49+
}
50+
$sqlStmt = 'WHERE ' . substr($sqlStmt, 0, -5);
51+
}
52+
$sqlStmt2 = '';
53+
if ($data2 == '') {
54+
} else {
55+
$columns = array_keys($data2);
56+
$values = array_values($data2);
57+
$clength = count($columns);
58+
for ($x = 0; $x < $clength; $x++) {
59+
$sqlStmt2 .= $columns[$x] . " " . $values[$x] . " ";
60+
}
61+
$sqlStmt2 = $sqlStmt2;
62+
}
63+
$Istr = "SELECT * FROM $tableName $sqlStmt $sqlStmt2";
64+
$stmtData = $this->dbObjectect->query_execute($Istr);
65+
if ($method == 'fetch') {
66+
while ($row = $stmtData->fetch_assoc()) {
67+
$arr[] = $row;
68+
}
69+
return $arr;
70+
} elseif ($method == 'count') {
71+
return $this->dbObjectect->query_rowCount($stmtData);
72+
}
73+
}
74+
function custom($data, $method)
75+
{
76+
$arr = array();
77+
$stmtData = $this->dbObjectect->query_execute("$data");
78+
if ($method == 'fetch') {
79+
while ($row = $stmtData->fetch_assoc()) {
80+
$arr[] = $row;
81+
}
82+
return $arr;
83+
} elseif ($method == 'count') {
84+
return $this->dbObjectect->query_rowCount($stmtData);
85+
} elseif ($method == 'update') {
86+
return 'ok';
87+
} elseif ($method == 'delete') {
88+
return 'ok';
89+
}
90+
}
91+
92+
function multiSelect($tableNames, $data, $method, $data2)
93+
{
94+
$sqlStmt = '';
95+
$sqlStmt2 = '';
96+
$arr = array();
97+
$TBStmt = '';
98+
//for tablesNames
99+
$TBcolumns = array_keys($tableNames);
100+
$TBvalues = array_values($tableNames);
101+
$TBclength = count($TBcolumns);
102+
for ($k = 0; $k < $TBclength; $k++) {
103+
$TBStmt .= $TBcolumns[$k] . " " . $TBvalues[$k] . ", ";
104+
}
105+
106+
$TBnames = substr($TBStmt, 0, -2);
107+
108+
//for data
109+
if ($data == '') {
110+
$sqlStmt = '';
111+
} else {
112+
$columns = array_keys($data);
113+
$values = array_values($data);
114+
$clength = count($columns);
115+
for ($x = 0; $x < $clength; $x++) {
116+
$sqlStmt .= $columns[$x] . " = '" . $values[$x] . "' and ";
117+
}
118+
$sqlStmt = 'WHERE ' . substr($sqlStmt, 0, -5);
119+
}
120+
if ($data2 == '') {
121+
$sqlStmt2 = '';
122+
} else {
123+
$columns = array_keys($data2);
124+
$values = array_values($data2);
125+
$clength = count($columns);
126+
for ($x = 0; $x < $clength; $x++) {
127+
$sqlStmt2 .= $columns[$x] . " " . $values[$x] . " ";
128+
}
129+
$sqlStmt2 = $sqlStmt2;
130+
}
131+
$Istr = "SELECT * FROM $TBnames $sqlStmt $sqlStmt2";
132+
$stmtData = $this->dbObjectect->query_execute($Istr);
133+
if ($method == 'fetch') {
134+
while ($row = $stmtData->fetch_assoc()) {
135+
$arr[] = $row;
136+
}
137+
return $arr;
138+
} elseif ($method == 'count') {
139+
return $this->dbObjectect->query_rowCount($stmtData);
140+
}
141+
}
142+
143+
144+
}

0 commit comments

Comments
 (0)