Skip to content

Commit f7009d8

Browse files
authored
Add files via upload
Upload file commit
1 parent 15201d5 commit f7009d8

File tree

9 files changed

+415
-0
lines changed

9 files changed

+415
-0
lines changed

src/Ext.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
require_once "autoload.php";
3+
require_once "constants.php";
4+
5+
use \qwerty\Database\DatabaseController as DatabaseController;
6+
use \qwerty\Config\Method as Method;
7+
8+
9+
$db = new DatabaseController(DBHost, DBName, DBUser, DBPassword,connection);
10+
11+
12+
$cn = $db->MysqlConnection();
13+
//$baglanti = $db->PostgresqlConnection();
14+
15+
$method = new Method($cn);
16+
17+
//$veri = $method->Select_all("orders");
18+
/*
19+
20+
$data = array(
21+
'ShipName' => "deneme",
22+
'ShipAddress' => "deneme",
23+
'ShipCity' => "deneme"
24+
);
25+
*/
26+
//$method = $method->Insert("orders",$data);
27+
28+
$id = array(
29+
'OrderID',"CustomerID"
30+
);
31+
32+
/*
33+
$data = array(
34+
'ShipName' => "12",
35+
'ShipAddress' => "12",
36+
'ShipCity' => "12"
37+
);
38+
39+
40+
$method = $method->Update('orders', $id, $data);
41+
*/
42+
43+
//$method = $method->Delete('orders',$id);
44+
45+
$data = array(
46+
"EmployeeID" => "4"
47+
);
48+
$con = array("!=");
49+
$if = array("AND");
50+
51+
//$a = $method->Select_ch("orders",$id);
52+
53+
$a = $method->Select_wh('orders',$data,$con,$if);
54+
55+
print_r($a);
56+
57+
58+
?>

src/autoload.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
spl_autoload_register(function ($classname){
4+
5+
include_once str_replace("\\","/", $classname) . '.php';
6+
7+
});
8+
9+
?>

src/constants.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
4+
define("localhost","localhost");
5+
define("dbname","sifirdanphp");
6+
define("dbuser","postgres");
7+
define("dbpass","489623sunA");
8+
define("connection1","connection");
9+
10+
define("DBHost","localhost");
11+
define("DBName","northwind");
12+
define("DBUser","root");
13+
define("DBPassword","");
14+
define("connection","connection");
15+
16+
17+
/*
18+
19+
$sql = "pgsql:host=localhost;port=5432;dbname=sifirdanphp";
20+
$user1 = "postgres";
21+
$sifre = "489623sunA";
22+
23+
24+
$dbhost = "localhost";
25+
$dbname = "sifirdanphp";
26+
$dbuser = "postgres";
27+
$dbpass = "489623sunA";
28+
$connection = "";
29+
*/
30+
31+
32+
?>

src/qwerty/Config/Method.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace qwerty\Config;
4+
5+
class Method extends Sql {
6+
7+
public $connection;
8+
9+
10+
public function __construct($connection){
11+
parent::__construct($connection);
12+
}
13+
14+
public function Select_ch($table,$data = array())
15+
{
16+
return parent::Select_ch($table,$data);
17+
}
18+
19+
public function Select_all($table){
20+
return parent::Select_all($table);
21+
}
22+
23+
public function Select_wh($table, $data = array(),$con = array(), $if = array())
24+
{
25+
return parent::Select_wh($table, $data, $con, $if); // TODO: Change the autogenerated stub
26+
}
27+
28+
public function Insert($table, $data = array())
29+
{
30+
return parent::Insert($table, $data); // TODO: Change the autogenerated stub
31+
}
32+
33+
public function Update($table, $id = array(), $data = array())
34+
{
35+
return parent::Update($table, $id, $data); // TODO: Change the autogenerated stub
36+
}
37+
public function Delete($table, $id = array())
38+
{
39+
return parent::Delete($table, $id); // TODO: Change the autogenerated stub
40+
}
41+
42+
43+
}
44+
45+
46+
?>

src/qwerty/Config/Sql.php

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
<?php
2+
3+
namespace qwerty\Config;
4+
5+
Abstract class Sql implements SqlPattern {
6+
7+
private $connetction;
8+
private $sql;
9+
private $query;
10+
private $rt;
11+
private $quote;
12+
private $res;
13+
14+
public function __construct($connetction)
15+
{
16+
$this->connetction = $connetction;
17+
}
18+
19+
public function Select_ch($table,$data = array())
20+
{
21+
array_keys($data);
22+
$qt = "";
23+
foreach(array_merge($data) as $item){
24+
$qt .= $item.", ";
25+
}
26+
$res = rtrim($qt,", ");
27+
28+
$this->sql = "Select ".$res." from ".$table;
29+
$this->query = $this->connetction->prepare($this->sql);
30+
$this->query->execute();
31+
32+
while($this->rt = $this->query->fetchAll()) {
33+
return $this->rt;
34+
};
35+
// TODO: Implement Select_ch() method.
36+
}
37+
38+
public function Select_all($table)
39+
{
40+
$this->sql = "Select * from ".$table;
41+
$this->query = $this->connetction->prepare($this->sql);
42+
$this->query->execute();
43+
44+
while($this->rt = $this->query->fetchAll()) {
45+
return $this->rt;
46+
};
47+
48+
49+
}
50+
51+
public function Select_wh($table,$data = array(),$con = array(),$if = array()){
52+
53+
54+
$q = "";
55+
$i = 0;
56+
$b = 1;
57+
foreach($data as $x => $val) {
58+
$q .= " $x ".$con[$i]." $val ".$if[$b - 1];
59+
$i++;
60+
}
61+
62+
$res = rtrim($q,"AND");
63+
64+
65+
$this->sql = "SELECT * FROM ".$table." WHERE ". $res;
66+
67+
$this->query = $this->connetction->prepare($this->sql);
68+
$this->query->execute();
69+
70+
while($this->rt = $this->query->fetchAll()) {
71+
return $this->rt;
72+
};
73+
74+
75+
76+
}
77+
78+
public function Insert($table, $data = array())
79+
{
80+
$quote = "";
81+
foreach (array_keys($data) as $item){
82+
$quote .= $item." = :". "$item, ";
83+
}
84+
$res = rtrim($quote,", ");
85+
86+
$this->sql = "INSERT INTO ".$table." SET " . $res;
87+
$this->query = $this->connetction->prepare($this->sql);
88+
$this->rt = $this->query->execute($data);
89+
if ($this->rt) {
90+
//return $this->connection->lastInsertId();
91+
return $this->rt;
92+
}
93+
94+
95+
// TODO: Implement Insert() method.
96+
}
97+
98+
public function Update($table, $id = array(), $data = array())
99+
{
100+
101+
$quete = "";
102+
103+
foreach($data as $x => $val) {
104+
$quete .= "$x = '$val', ";
105+
}
106+
107+
$res = rtrim($quete,", ");
108+
109+
$wher = "";
110+
111+
foreach($id as $x => $val) {
112+
$wher .= "$x = $val, ";
113+
}
114+
115+
$wh = rtrim($wher,", ");
116+
117+
118+
$this->sql = "UPDATE ".$table." SET " . $res . " WHERE ".$wh.";";
119+
120+
$this->query = $this->connetction->prepare($this->sql);
121+
122+
$this->rt = $this->query->execute();
123+
if ($this->rt) {
124+
return $this->rt;
125+
126+
}
127+
128+
}
129+
130+
public function Delete($table, $id = array())
131+
{
132+
133+
$wher = "";
134+
135+
foreach($id as $x => $val) {
136+
$wher .= "$x = $val, ";
137+
}
138+
139+
$wh = rtrim($wher,", ");
140+
141+
$this->sql = "DELETE FROM ".$table." WHERE ".$wh.";";
142+
$this->query = $this->connetction->prepare($this->sql);
143+
$this->rt = $this->query->execute();
144+
if ($this->rt) {
145+
return $this->rt;
146+
147+
}
148+
}
149+
150+
151+
152+
153+
}
154+
155+
156+
157+
158+
?>

src/qwerty/Config/SqlPattern.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace qwerty\Config;
4+
5+
interface SqlPattern{
6+
7+
public function __construct($connection);
8+
public function Select_ch($table,$data = array());
9+
public function Select_All($table);
10+
public function Select_wh($table,$data = array(),$con = array(), $if = array());
11+
public function Insert($table,$data = array());
12+
public function Update($table, $id = array(), $data = array());
13+
public function Delete($table, $id = array());
14+
}

src/qwerty/Database/Database.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace qwerty\Database;
4+
5+
use \PDO;
6+
7+
abstract class Database implements DatabaseFace {
8+
9+
protected $dbhost;
10+
protected $dbname;
11+
protected $dbuser;
12+
protected $dbpass;
13+
protected $connection;
14+
15+
public function __construct($dbhost, $dbname, $dbuser, $dbpass, $connection)
16+
{
17+
$this->dbhost = $dbhost;
18+
$this->dbname = $dbname;
19+
$this->dbuser = $dbuser;
20+
$this->dbpass = $dbpass;
21+
$this->connection = $connection;
22+
23+
}
24+
25+
26+
public function MysqlConnection(){
27+
$this->connection = new PDO("mysql:host=".$this->dbhost.";dbname=".$this->dbname.";charset=utf8", $this->dbuser, $this->dbpass);
28+
return $this->connection;
29+
//echo "accept";
30+
}
31+
32+
public function PostgresqlConnection(){
33+
$this->connection = new PDO("pgsql:host=".$this->dbhost.";port=5432;dbname=".$this->dbname.";",$this->dbuser,$this->dbpass);
34+
//echo "accept";
35+
return $this->connection;
36+
37+
}
38+
39+
40+
41+
}
42+
43+
44+
45+
?>
46+

0 commit comments

Comments
 (0)