PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of vinaykant sahu   Database class for MySQL using PDO   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: test file
Class: Database class for MySQL using PDO
Connect and access MySQL databases using PDO
Author: By
Last change:
Date: 7 years ago
Size: 1,520 bytes
 

Contents

Class file image Download
<?php required_once('config.php');
   
required_once('class/class.Database.php');
    
   
$dbObj = new Database();
    
   
//to get list
    
   
$query = '
                SELECT
                    *
                FROM
                    test1
                WHERE
                    test1.abc = :ABC
                    AND
                    test1.xyz = :XYZ
            '
;
   
$stmt = $dbObj->prepare($query);
   
   
$dbObj->bind($stmt, ':ABC', $abc);
   
$dbObj->bind($stmt, ':XYZ', $xyz);
   
   
$dbObj->execute($stmt);
   
    if (!empty(
$dbObj->displayError())) {
        throw new
Exception($dbObj->displayError());
    }

   
$list = $dbObj->fetchSqlData($stmt);
   
   
// To Insert
   
$query = '
                INSERT INTO
                    test1
                    (
                        abc,
                        efg,
                        xyz
                    )
                VALUES
                    (
                        :ABC,
                        :EFG,
                        :XYZ
                    )
            '
;
   
$stmt = $dbObj->prepare($query);
   
   
$dbObj->bind($stmt, ':ABC', $abc);
   
$dbObj->bind($stmt, ':EFG', $efg);
   
$dbObj->bind($stmt, ':XYZ', $xyz);
   
   
$dbObj->execute($stmt);
   
    if (!empty(
$dbObj->displayError())) {
        throw new
Exception($dbObj->displayError());
    }
   
   
// To Insert multiple rows
   
$query = '
                INSERT INTO
                    test1
                    (
                        abc,
                        efg,
                        xyz
                    )
                VALUES
            '
;
   
$insertSql = [];
    for (
$index = 1; $index < 1000; $index++) {
       
$nameIndex = 'EFG_'.$index; //dummy data
       
$rank = $index * 10; //dummy data
       
       
$insertSql[] = sprintf(
               
"( %d, %d, %d)",
               
$index,
               
$nameIndex,
               
$rank
           
);
    }
   
$dbObj->saveMultipleInsertQuery($query, $insertSql);