Build CRUD Application PHP & Mysql

Home » Tutorials » PHP+MySQL » Build CRUD Application PHP & Mysql
Starting from today lesson we will begin to build simplest web application with php and mysql. It will be use sport database, which we created last lessons. Today we’ll define structure of our app, write script to connect with database and build html skeleton of our application
The structure is below:

  1. Config – connect with database (db.php)
  2. Teams (teams.php) – list of teams with the possibility of editing information about team
  3. Players (players.php) – list of players with the possibility of editing information about player
  4. Countries (countries.php) – list of teams by countries.

In my projects I use PDO for work with databases. There are another variants, for example, mysql and mysqli. I notice, that mysql extension is deprecated from php 5.5 and removed from php 7.
Why do I use PDO? PDO is universal decision for working with databases. It can work with different databases. And it is easy to change database in your application. Next details with PDO working we will consider in next lessons, while writing code of our app.

Also you will know about try.catch construction. When can you use it? There are arise different errors (logical and so on), but sometimes you can provide for and handle this errors. For example, you may understand, attempt with database connection can finish with error. This error you need to provide.

try...catch example

try {
$db = new PDO("mysql:host=localhost;dbname=sport", $user, $password);
} catch (Exception $e) {
echo $e->getMessage();
After success connection we will write html skeleton of our app using bootstrap and jquery.

Code lesson (db.php)

<?php $user = "root"; $password = "29061990"; /*Почему данный код является избыточным? Оставляйте ответы в комментариях*/
try {
$db = new PDO("mysql:host=localhost;dbname=sport", $user, $password);
} catch (Exception $e) {
echo $e->getMessage();

Code lesson (index.php)

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<link href="//" rel="stylesheet">
<script src=""></script>
<script src=""></script>

    <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <a class="navbar-brand" href="#">Sport CRM</a>
            <div class="collapse navbar-collapse navbar-ex1-collapse">
                <ul class="nav navbar-nav">
                    <li><a href="index.php">Главная</a></li>
                    <li><a href="players.php">Игроки</a></li>
                    <li><a href="teams.php">Команды</a></li>
                    <li><a href="countries.php">Страны</a></li>

<div id="content">



Submit a Comment

Your email address will not be published. Required fields are marked *

Подписаться на рассылку

Будьте в курсе - получайте последние статьи на свой email

Ваша подписка успешно оформлена

Pin It on Pinterest

Share This