-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_db.php
91 lines (75 loc) · 2.49 KB
/
create_db.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
<?php
echo "<br />Creating db now....";
$dbhost="den1.mysql2.gear.host";
$dbuser="webtechdb";
$dbpass="webtechdb!";
$dbname="webtechdb";
$db = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::MYSQL_ATTR_FOUND_ROWS, true);
try {
$sql_create_contacts_tbl =
CREATE TABLE IF NOT EXISTS contacts (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(150) NOT NULL,
email varchar(250) NOT NULL,
mobileno varchar(15) NOT NULL,
photo varchar(150) NOT NULL DEFAULT 'default.png',
ownerlogin varchar(50) NOT NULL,
addeddate datetime NOT NULL,
status int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1
EOSQL;
$result = $db->exec($sql_create_contacts_tbl);
if($result !== false){
echo "<br/>Table contacts created....";
} else {
echo "<br/>Error creating table contacts!";
}
}
catch(PDOException $e) {
$errorMessage = $e->getMessage();
echo "<br />$errorMessage";
}
try {
$sql_create_users_tbl =
CREATE TABLE IF NOT EXISTS users (
id int(11) NOT NULL AUTO_INCREMENT,
login varchar(50) NOT NULL,
password varchar(250) NOT NULL,
name varchar(150) NOT NULL,
email varchar(250) NOT NULL,
mobileno varchar(15) NOT NULL,
photo varchar(150) NOT NULL DEFAULT 'default.png',
addeddate datetime NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
EOSQL;
$result = $db->exec($sql_create_users_tbl);
if($result !== false){
echo "<br/>Table users created....";
} else {
echo "<br/>Error creating table users!";
}
}
catch(PDOException $e) {
$errorMessage = $e->getMessage();
echo "<br />$errorMessage";
}
try {
$sql_insert_user_into_users =
INSERT INTO users (login, password, name, email, mobileno, photo, addeddate) VALUES ('baba', 'b42a6d93d7969152e0f18f0e41c0f4f2bc9625f06c43dcbc22f6ffb2ffdd6137d93c1cdbb16', 'ali', '[email protected]', '0123456789', 'default.png', NOW());
EOSQL;
$result = $db->exec($sql_insert_user_into_users);
if($result !== false){
echo "<br/>User ali created....";
} else {
echo "<br/>Error inserting user ali!";
}
}
catch(PDOException $e) {
$errorMessage = $e->getMessage();
echo "<br />$errorMessage";
}