PHP with PDO (PHP Data Objects) Quickstart

Overview

PHP with PDO (PHP Data Objects) Quickstart

This repository contains a simple web application that demonstrates how to quickly connect to and communicate with a MariaDB database using PHP and PDO (PHP Data Objects).

⚠️ Interested in using MariaDB and PHP with mysqli? Check out the quickstart here!

Getting Started

The application in this repository demonstrates how to:

  • Connect to a MariaDB database using PDO (PHP Data Objects)
  • Execute queries (SELECT, UPDATE, INSERT and DELETE) to manage contact data (like a digital rolodex)
  • Use prepared statements

Prepare the database

The application relies on a single database (rolodex) that contains a single table (contacts). You can find the necessary SQL for setting up the environment in schema.sql.

Run the application

After you've pulled down this repository, follow these steps to get the app up and running:

  1. Update the database configuration settings in src/config.php (which is used across the app) to point to your MariaDB database.

    Example configuration:

    false, // Disable emulation mode for "real" prepared statements PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Disable errors in the form of exceptions PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Make the default fetch be an associative array ]; $pdo = new PDO($dsn, "app_user", "Password123!", $options);">
    $dsn = "mysql:host=127.0.0.1;dbname=rolodex;charset=utf8mb4";
    
    $options = [
    PDO::ATTR_EMULATE_PREPARES   => false, // Disable emulation mode for "real" prepared statements
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION, // Disable errors in the form of exceptions
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Make the default fetch be an associative array
    ];
    
    $pdo = new PDO($dsn, "app_user", "Password123!", $options);
  2. Within the src directory, run the application using the built-in web server.

    $ php -S localhost:5000

Helpful Resources

Support and Contribution

Please feel free to submit PR's, issues or requests to this project directly.

If you have any other questions, comments, or looking for more information on MariaDB please check out:

Or reach out to us directly via:

License

License

You might also like...
Silverstripe-searchable - Adds to the default Silverstripe search by adding a custom results controller and allowing properly adding custom data objects and custom fields for searching

SilverStripe Searchable Module UPDATE - Full Text Search This module now uses Full Text Support for MySQL/MariaDB databases in version 3.* Adds more c

Melek Berita Backend is a service for crawling data from various websites and processing the data to be used for news data needs.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

:date: The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects

sabre/vobject The VObject library allows you to easily parse and manipulate iCalendar and vCard objects using PHP. The goal of the VObject library is

Enforced disposal of objects in PHP. 🐘

Enforced disposal of objects in PHP. This package provides a Disposable interface and using() global function that can be used to enforce the disposal

Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

SAPI request and response objects for PHP 8.1

Sapien This package provides server API (SAPI) request and response objects for PHP 8.1: Sapien\Request, composed of readonly copies of PHP supergloba

Collection of value objects that represent the types of the PHP type system

sebastian/type Collection of value objects that represent the types of the PHP type system. Installation You can add this library as a local, per-proj

A PHP 7 value objects helper library.

valueobjects Requirements Requires PHP = 7.1 Installation Through Composer, obviously: composer require funeralzone/valueobjects Extensions This lib

php String Objects Chains like length,forEach,filter,replace,repalcAll much More.... Module

php String Objects Chains like length,forEach,filter,replace,repalcAll much More.... Module

Owner
Developer Code Central
MariaDB Developer Code Samples and Examples
Developer Code Central
Voice Quickstart Server in PHP

Programmable Voice: Quickstart Application Server - PHP This repository contains the server-side web application required to run the Twilio Programmab

Twilio 8 Mar 29, 2020
PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects.

?? Yell PHP package to make your objects strict and throw exception when you try to access or set some undefined property in your objects. Requirement

Zeeshan Ahmad 20 Dec 8, 2018
Deeper is a easy way to compare if 2 objects is equal based on values in these objects. This library is heavily inspired in Golang's reflect.DeepEqual().

Deeper Deeper is a easy way to compare if 2 objects is equal based on values in these objects. This library is heavily inspired in Golang's reflect.De

Joubert RedRat 4 Feb 12, 2022
CRUD PHP, SQL PDO

PHP-Mastering CRUD em PHP usando MySQL PDO; Configure a ficheiro config.php de acordo com a sua configuração da base de dados PHP CRUD using PDO MySQL

BaltonCome 4 Jun 2, 2022
Aqui são distribídas apostilas sobre alguns assuntos como PHP, PDO, MySQL, PHPOO, MVC, etc

Apostilas de Programação Aqui são distribídas apostilas sobre alguns assuntos como PHP, PDO, MySQL, PHPOO, MVC, etc URL deste repositório https://gith

Ribamar FS 50 Dec 24, 2022
Personal PHP MySQL query handler based on Eloquent using PDO.

?? Equivoluent Welcome to "Equivoluent" my personal PHP MySQL query handler using PDO. Equivoluent is based on Laravel's Eloquent. The goal of "Equivo

Wob Jelsma 2 Sep 7, 2022
Sistema de login usando PHP, MySQL(PDO),HTML,CSS e bootstrap

sistemalogin link para entrar no projeto: https://williamsistema.000webhostapp.com/ Sistema de login usando PHP, MySQL(PDO),HTML,CSS e bootstrap Requi

William Lima Alves 4 Oct 7, 2022
QueryHandler - Handling PDO ' s query with mySQL database

QueryHandler this class's method are static .... that mean you don't need to create an object to use it . All methodes will return an Exception if it

null 7 Aug 9, 2022
Samsui is a factory library for building PHP objects useful for setting up test data in your applications.

#Samsui Samsui is a factory library for building PHP objects useful for setting up test data in your applications. It is mainly inspired by Rosie for

Sam Yong 31 Nov 11, 2020
Dobren Dragojević 6 Jun 11, 2023