-
Notifications
You must be signed in to change notification settings - Fork 6
/
insert.php
125 lines (110 loc) · 3.79 KB
/
insert.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
<?php
require 'config.php';
require 'bankalar.php';
$messages = [];
try {
$db = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME . ';charset=utf8', DB_USER, DB_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
array_push($messages, [
'class' => 'alert alert-success',
'message' => 'Veritabanına bağlandıldı.'
]);
$tableExists = $db->query('SHOW TABLES LIKE "'.DB_TABLE_NAME.'"')->rowCount();
if ($tableExists) {
array_push($messages, [
'class' => 'alert alert-warning',
'message' => '"'.DB_TABLE_NAME.'" tablosu mevcut'
]);
} else {
// sql to create table
$sql = "CREATE TABLE IF NOT EXISTS ".DB_TABLE_NAME." (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(128) NOT NULL,
address VARCHAR(255),
telephone VARCHAR(16),
fax VARCHAR(16),
web VARCHAR(64),
telex VARCHAR(32),
eft VARCHAR(4),
swift VARCHAR(16)
)ENGINE=MyISAM DEFAULT CHARSET=utf8";
$db->exec($sql);
array_push($messages, [
'class' => 'alert alert-success',
'message' => '"'.DB_TABLE_NAME.'" isimli tablo oluşturuldu.'
]);
}
$insert_query = $db->prepare("INSERT INTO ".DB_TABLE_NAME." SET
name = :name,
address = :address,
telephone = :telephone,
fax = :fax,
web = :web,
telex = :telex,
eft = :eft,
swift = :swift
");
$count = 0;
foreach($banks as $bank)
{
$query = $db->query("SELECT * FROM ".DB_TABLE_NAME." WHERE name = '".$bank['name']."'");
if ( $query->rowCount() ){
array_push($messages, [
'class' => 'alert alert-warning',
'message' => '"'.$bank['name'].'" isimli banka mevcut olduğu için oluşturulmadı.'
]);
}
else{
$insert = $insert_query->execute([
"name" => $bank['name'],
"address" => $bank['address'],
"telephone" => $bank['telephone'],
"fax" => $bank['fax'],
"web" => $bank['web'],
"telex" => $bank['telex'],
"eft" => $bank['eft'],
"swift" => $bank['swift'],
]);
if ( $insert ){
$count++;
array_push($messages, [
'class' => 'alert alert-success',
'message' => '"'.$bank['name'].'" isimli banka '.$db->lastInsertId().' id ile oluşturuldu.'
]);
}
}
}
if($count)
{
array_push($messages, [
'class' => 'alert alert-success',
'message' => 'Toplam '.$count.' adet kayıt oluşturuldu.'
]);
}
} catch (PDOException $e) {
array_push($messages, [
'class' => 'alert alert-danger',
'message' => 'Sorry.. Database Problem! Error' . $e->getMessage()
]);
}
?>
<!doctype html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<title>Insert Banks</title>
</head>
<body>
<div class="container">
<?php
foreach ($messages as $message) {
echo '<div class="' . $message['class'] . '">' . $message['message'] . '</div>';
}
?>
</div>
</body>
</html>