Last active
January 13, 2019 18:05
-
-
Save theArjun/66379efc28c64dbf102130a12eae8d8d to your computer and use it in GitHub Desktop.
PHP Database Connect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $conn = mysqli_connect("localhost","root",""); | |
| if(!$conn){ | |
| die("Host connection failed.<br/>"); | |
| }else{ | |
| echo "Host connected.<br/>"; | |
| } | |
| $create_db = "CREATE DATABASE authentication"; | |
| $create_db_result = mysqli_query($conn,$create_db); | |
| if(!$create_db_result){ | |
| echo "Couldn't create database.<br/>"; | |
| }else{ | |
| echo "Database created.<br/>"; | |
| } | |
| $connect_db = mysqli_select_db($conn,'authentication'); | |
| if(!$connect_db){ | |
| echo "Couldn't create database connection.<br/>"; | |
| }else{ | |
| echo "Database connection created.<br/>"; | |
| } | |
| $create_table_query = "CREATE TABLE users (id INT(2) AUTO_INCREMENT PRIMARY KEY, username VARCHAR(32) NOT NULL, pwd VARCHAR(32) NOT NULL)"; | |
| $create_table = mysqli_query($conn,$create_table_query); | |
| if(!$create_table){ | |
| echo "Couldn't create table.<br/>"; | |
| }else{ | |
| echo "Table created successfully.<br/>"; | |
| } | |
| $add_record_query = "INSERT INTO `authentication`.`users`(`id`,`username`,`pwd`)VALUES('10','arjun','adhikari')"; | |
| $add_record = mysqli_query($conn,$add_record_query); | |
| if(!$add_record){ | |
| echo "Couldn't update record.<br/>"; | |
| }else{ | |
| echo "Record updated successfully.<br/>"; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment