Building a PHP/MySQL Crud App Part 1

John Wolfe
2 min readMay 21, 2018

This week I set out take my PHP skills to the next level by beginning a CRUD App that would incorporate MySQL and Bootstrap.

The first part of this project involved going into the HTDOCs and starting a new project called Crud and then creating an index.php file.

I next set up the connection to the MySQL Database. For my APACHE server I use MAMP. I then went into the phpMyAdmin interface and created a new database named crudapp. Next, I created a config folder with a db.php file. Inside this file, the connection with the MySQL database was established through the following code:

$host = 'localhost';$user = 'root';$password = 'root';$db_name = "crudapp";$connection = mysqli_connect($host, $user, $password, $db_name);if (!$connection) {die("CONNECTION TO DB FAILED. " . mysqli_error($connection));}

The variable declarations establish the specific login information to the database, including the $db_name. The PHP method mysqli_connect is then used to attempt to connect to the database. An if conditional is then used to check whether or not the $connection was successful and if it’s not then it using the php die and mysqli methods it appends the information to the screen.

In addition to the MySQL connection, I additionally built out a session method:

--

--

John Wolfe

Software developer Tata Consultancy Services. React, Rails, and Java. Former content editor for @Quora and @inversedotcom. I live in Chicago, Illinois.