/************************************************************************/
/* 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();
|