PHP, MySQL & Stripe API Payment App – Part 1 – Download

In this video series we will build a PHP payment page that accepts credit cards using the stripe API and also stores the data in a MySQL database using PDO. We will be creating tables and models for customers and transactions to store them in the database and retrieve them within the app.

SPONSOR: Eduonix Machine Learning Course

CODE: Github Repo

Stripe API Docs: Card Element Quickstart

PDO Class Gist:

* Connects Database Using PDO
* Creates Prepeared Statements
* Binds params to values
* Returns rows and results
class Database {
private $host = DB_HOST;
private $user = DB_USER;
private $pass = DB_PASS;
private $dbname = DB_NAME;
private $dbh;
private $error;
private $stmt;
public function __construct() {
// Set DSN
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
$options = array (
// Create a new PDO instanace
try {
$this->dbh = new PDO ($dsn, $this->user, $this->pass, $options);
} // Catch any errors
catch ( PDOException $e ) {
$this->error = $e->getMessage();
// Prepare statement with query
public function query($query) {
$this->stmt = $this->dbh->prepare($query);
// Bind values
public function bind($param, $value, $type = null) {
if (is_null ($type)) {
switch (true) {
case is_int ($value) :
$type = PDO::PARAM_INT;
case is_bool ($value) :
$type = PDO::PARAM_BOOL;
case is_null ($value) :
$type = PDO::PARAM_NULL;
default :
$type = PDO::PARAM_STR;
$this->stmt->bindValue($param, $value, $type);
// Execute the prepared statement
public function execute(){
return $this->stmt->execute();
// Get result set as array of objects
public function resultset(){
return $this->stmt->fetchAll(PDO::FETCH_OBJ);
// Get single record as object
public function single(){
return $this->stmt->fetch(PDO::FETCH_OBJ);
// Get record row count
public function rowCount(){
return $this->stmt->rowCount();
// Returns the last inserted ID
public function lastInsertId(){
return $this->dbh->lastInsertId();

view raw
hosted with ❤ by GitHub

PHP OOP Udemy Course:

BECOME A PATRON: Show support & get perks!

Website & Udemy Courses

Follow Traversy Media:

The Developer Hangout: Public Discord Server


Do you love us?, Please donate to us ,thank you. BTC 38WPVc3xMYmoMp1GcnpDXd1fEzbfgujsCB Etherum 0x6c11844FD079b2490CDd44039e1C2f0940d098dc

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.