PHP Classes

Database class for MySQL using PDO: Connect and access MySQL databases using PDO

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 238 All time: 8,055 This week: 455Up
Version License PHP version Categories
mysql-using-pdo 1.0.0Freeware5PHP 5, Databases
Description 

Author

This class can connect and access MySQL databases using PDO.

It can connect to a given MySQL database database and perform several types of database access operations. Currently it can:

- Execute queries with prepared statements using parameters from an array
- Retrieve all query results into an array
- Manage transactions
- Retrieve the query row count and last inserted record identifier

Picture of vinaykant sahu
Name: vinaykant sahu <contact>
Classes: 2 packages by
Country: India India

Example

<?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);
   
   


  Files folder image Files (3)  
File Role Description
Files folder imageclass (1 file)
Accessible without login Plain text file config.php Conf. configuration parameters
Accessible without login Plain text file test.php Example test file

  Files folder image Files (3)  /  class  
File Role Description
  Plain text file class.Database.php Class Source Class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:238
This week:0
All time:8,055
This week:455Up