Skip to content

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).

License

Notifications You must be signed in to change notification settings

mariadb-developers/php-pdo-quickstart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

    $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

About

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).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published