PHP Classes
elePHPant
Icontem

PDO database: Database access wrapper using PDO

Recommend this page to a friend!
  Info   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2014-09-22 (2 years ago) RSS 2.0 feedNot enough user ratingsTotal: 534 All time: 5,337 This week: 1,068Up
Version License PHP version Categories
pdo-database-wrapper 1.3GNU General Publi...5.0PHP 5, Databases
Description Author

This class is a database access wrapper using PDO. It can:

- Connect to a given database server
- Execute SQL prepared queries using given parameters
- Return query results for SELECT like queries, or return the number of affected rows for other types of queries

Picture of Julio Alvarado
Name: Julio Alvarado <contact>
Classes: 1 package by
Country: United States United States

Details
/************************************************************************/
/* My Database Connection
/* http://
/* Copyright © 2010 by Julio Alvarado
/************************************************************************/
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/


How to connect:

$DATABASE = array(
    	"dsn" 		=> "mysql:host=localhost;port=3306;dbname=mydb",
   
			"username" 	=> "root",
    
			"password" 	=> "password"
    
		);

$db = new db($DATABASE);

if($db->connect()) {
	//Do Somthing 
}else{
	die($db->error());
}


Select, Insert, Update and delete Data:
	
	$data = $db->exec($sqlselectstatement, $fetchtype , $fetchstyle, $bindings);

	A: Sql statements:	(required)
		"Select * from Mydb"
		"INSERT Mydb (name, status, description) VALUES (:name, :status, :description)";
		"UPDATE Mydb SET name = :name, status = :status, description = :description WHERE id = :id";
		"DELETE FROM Mydb WHERE id = :id";

	B: Fetch Types: (optional)
		A: fetch
		B: fetchAll
		C: fetchColumn
		D: fetchObject

	C: Fetch Style:
		PDO::FETCH_ASSOC
		PDO::FETCH_BOTH (default) 
		PDO::FETCH_BOUND
		PDO::FETCH_INTO
		PDO::FETCH_LAZY
		PDO::FETCH_NAMED
		PDO::FETCH_NUM
		PDO::FETCH_OBJ

	D: Bindings: (depending on statement)
		$bindings = array("name" => $name, "status" => $status, "description" => $description, "id" => $id);

you can run diectly to execution(for no response back) only errors
	$data = $db->execution($sqlselectstatement, $bindings);



other functions 
	Rowcount: (gets row count for selection)
		$mycount = $db->rowcount($sql->Select); 
	ColCount: (gets column count for selection)
		$mycount = $db->colcount($sql->Select); 
	Close: (Closes Connection)
		$db->Close(); 
	Error:(error catching)
		$db->error(); 
  Files folder image Files  
File Role Description
Plain text file pdo_database.php Class PDO Database Class
Plain text file Readme.txt Doc. Readme

 Version Control Unique User Downloads Download Rankings  
 0%
Total:534
This week:0
All time:5,337
This week:1,068Up