Konnor's Blog

PHP for Beginners - Part 8 - What the heck is PDO?

November 23, 2019

Okay, lets continue where we left off with MySQL prior to learning classes.

First, make sure your MySQL still works. Ensure you have a usable database for use by the PDO builtin class for PHP.

$ mysql
$ -> create database mytodo; # Create the database
$ -> show databases # Ensure it appears
$ -> exit

Alright, now lets dive in.

// index.php
<?php
try {
$pdo = new PDO('mysql:host=127.0.0.1;dbname=mytodos', 'root', 'Medic12!');
} catch(PDOException $e) {
die('could not connect.');
}
require 'index.view.php';



Written by Konnor Rogers who currently works as a paramedic looking to transition into becoming a full time software developer. You should follow him on Twitter