Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <?php
- //CONNECTION
- $dbhost="localhost";
- $dbuser="root";
- $dbpass="";
- $conn=mysqli_connect($dbhost,$dbuser,$dbpass);
- if($conn->connect_error)
- {
- die("<br>Connection failed: ".$conn->connect_error);
- }
- else
- {
- echo"<br>Connection successfull!";
- }
- //CREATING DATABASE
- $q1="CREATE DATABASE BOOKS";
- if($conn->query($q1)===TRUE)
- {
- echo"<br>Database BOOKS created!";
- }
- else
- {
- echo"<br>Error creating database: ".$conn->error;
- }
- //CONNECTING TO DATABASE BOOKS
- $dbhost="localhost";
- $dbuser="root";
- $dbpass="";
- $db="BOOKS";
- $conn=mysqli_connect($dbhost,$dbuser,$dbpass,$db);
- if($conn->connect_error)
- {
- die("<br>Connection failed: ".$conn->connect_error);
- }
- else
- {
- echo"<br>Connection to database ".$db." successfull!";
- }
- //CREATING TABLE
- $q2="CREATE TABLE BOOK_DETAILS(BOOKID INT(3) PRIMARY KEY NOT NULL,AUTHOR VARCHAR(20) NOT NULL,TITLE VARCHAR(30) NOT NULL)";
- if($conn->query($q2)===TRUE)
- {
- echo"<br>Table BOOK_DETAILS created successfully!";
- }
- else
- {
- echo"<br>Error creating table: ".$conn->error;
- }
- //INSERTING MULTIPLE QUERIES
- $sql="INSERT INTO BOOK_DETAILS(BOOKID,AUTHOR,TITLE) VALUES(200,'H.G.Wells','Invisible Man');";
- $sql.="INSERT INTO BOOK_DETAILS(BOOKID,AUTHOR,TITLE) VALUES(257,'Jonathan Swift','Gullivers Travel');";
- $sql.="INSERT INTO BOOK_DETAILS(BOOKID,AUTHOR,TITLE) VALUES(258,'Jules Verne','Around the World in 80 days');";
- $sql.="INSERT INTO BOOK_DETAILS(BOOKID,AUTHOR,TITLE) VALUES(279,'Khushwant Singh','A History of Sikhs');";
- $sql.="INSERT INTO BOOK_DETAILS(BOOKID,AUTHOR,TITLE) VALUES(186,'G.G.Shaw','Man and Superman');";
- if($conn->multi_query($sql)===TRUE)
- {
- echo"<br>New records created successfully!";
- }
- else
- {
- echo"<br>Error: ".$sql."<br>".$conn->error;
- }
- $conn->close();
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement