-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdao.php
92 lines (70 loc) · 2.76 KB
/
dao.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
<?php
function connect(){
$server = "localhost";
$user = "root";
$password = "";
$database = "quotedb";
$link = mysqli_connect($server,$user,$password);
if(!$link) {
die("Error connecting to the database");
}
$db = mysqli_select_db($link,$database);
if(!$db) {
$sql = "CREATE DATABASE IF NOT EXISTS $database";
if(mysqli_query($link, $sql)) {
echo "<script> console.log('database $database created');</script>";
} else {
echo "<script> console.log('couldn\'t create database');</script>";
}
$sql2 = "CREATE TABLE `quotedb`.`quotes` ( `quote_text` VARCHAR(1000) NOT NULL , `quote_author` VARCHAR(50) NOT NULL ) ENGINE = InnoDB;";
if(mysqli_query($link, $sql2)) {
echo "<script> console.log('database table created');</script>";
} else {
echo "<script> console.log('couldn\'t create table');</script>";
}
$sql1 = "INSERT INTO `quotedb`.`quotes` (quote_text, quote_author) VALUES (
'The best way to get a project done faster is to start sooner','Jim Highsmith'
),
(
'The first 90 percent of the code accounts for the first 90 percent of the development time...The remaining 10 percent of the code accounts for the other 90 percent of the development time.','Tom Cargill'
),
(
'Software innovation, like almost every other kind of innovation, requires the ability to collaborate and share ideas with other people, and to sit down and talk with customers and get their feedback and understand their needs.','Bill Gates'
),
(
'The bearing of a child takes nine months, no matter how many women are assigned. Many software tasks have this characteristic because of the sequential nature of debugging.','Fred Brooks'
),
(
'That\'s the thing about people who think they hate computers. What they really hate is lousy programmers.','Larry Niven'
),
(
'It is not enough for code to work.','Robert C. Martin'
),
(
'Any fool can write code that a computer can understand. Good programmers write <code></code> that humans can understand.','Martin Fowler'
)";
if(mysqli_query($link,$sql1)) {
echo "<script> console.log('database updated');</script>";
} else {
echo "<script> console.log('couldn\'t update database');</script>";
}
}
return mysqli_connect($server,$user,$password,$database);
}
function query(){
$query = "SELECT * FROM quotes";
$quotes = array();
if ($result = mysqli_query(connect(),$query)) {
while ($v = mysqli_fetch_array($result)) {
array_push($quotes, $v);
}
return $quotes;
}
}
function getQuote() {
$rand = mt_rand(0,6);
$array = query();
mysqli_close(connect());
return $array[$rand];
}
?>