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
try {
$pdo = new PDO('mysql:host=;dbname=mytodos', 'root', 'Medic12!');
} catch(PDOException $e) {
die('could not connect.');
require 'index.view.php';

Written by Konnor Rogers who currently works at VeueLive as a full time developer. You should follow him on Twitter