PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Name Removed   PDO Prepared MySQL Statements Class   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example
Class: PDO Prepared MySQL Statements Class
Prepare and execute MySQL queries using PDO
Author: By
Last change: Updated to version 2.0!

@Removed type and length parameters from both query() and fetch().The class determines the type and the length of the parameters passed.

@Removed connect() and the try-catch block.Use try-catch outside of the class to catch any possible exception.
Date: 8 years ago
Size: 1,020 bytes
 

Contents

Class file image Download
<?php
// @ PDO Prepared MySQL Statements Class v2.0 - Example
// @ Developed by Takis Maletsas
// @ 2016
require_once 'pdo.class.php';

try {
   
   
$db = new DB;
   
$db->query("CREATE TABLE my_table ( col1 VARCHAR(255), col2 INT, col3 VARCHAR(5) )");
   
$db->query("INSERT INTO my_table (col1,col2,col3) VALUES (?,?,?)", "Value1", 123, true);
   
   
$rows = $db->fetch("SELECT * FROM my_table WHERE col1=?", "Value1");
    echo
$rows[0]['col2'] . "</br>";
   
var_dump($rows[0]);
   
var_dump($rows);
   
   
$rows = $db->fetch("SELECT * FROM my_table WHERE col2=? AND col3=?", 123, true);
    echo
$rows[0]['col1'] . "</br>";
   
var_dump($rows[0]);
   
var_dump($rows);
   
   
$db->query("UPDATE my_table SET col1=?, col3=? WHERE col2=?", "Value2", true, 123);
   
   
$rows = $db->fetch("SELECT * FROM my_table");
    echo
$rows[0]['col1'] . "</br>";
   
var_dump($rows[0]);
   
var_dump($rows);
   
}
catch (
Exception $e) {
   
    exit(
$e->getMessage());
   
}
?>