forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbinit.php
More file actions
54 lines (50 loc) · 1.38 KB
/
dbinit.php
File metadata and controls
54 lines (50 loc) · 1.38 KB
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
<! Database Initiator>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$dbselect = mysql_select_db( 'simple_blog_db' );
if(! $dbselect)
{
$sql = 'CREATE Database simple_blog_db'; /* Make new database */
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not create database: ' . mysql_error());
}
/* Make new table for posts */
$sql = 'CREATE TABLE posts( '.
'post_id INT NOT NULL AUTO_INCREMENT, '.
'post_title VARCHAR(20) NOT NULL, '.
'post_date VARCHAR(20) NOT NULL, '.
'post_content VARCHAR(200) NOT NULL, '.
'primary key ( post_id ))';
mysql_select_db('simple_blog_db');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not create table: ' . mysql_error());
}
/* Make new table for comments */
$sql = 'CREATE TABLE comments( '.
'comment_id INT NOT NULL AUTO_INCREMENT, '.
'post_id INT NOT NULL, '.
'name VARCHAR(20) NOT NULL, '.
'email VARCHAR(20) NOT NULL, '.
'comment_content VARCHAR(200) NOT NULL, '.
'comment_time timestamp(6) NOT NULL'.
'primary key ( comment_id ))';
mysql_select_db('simple_blog_db');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not create table: ' . mysql_error());
}
}
mysql_close($conn);
?>