PHP Classes

File: DatabaseQueriesExample.php

Recommend this page to a friend!
  Classes of Sujay Bhowmick   Database Queries   DatabaseQueriesExample.php   Download  
File: DatabaseQueriesExample.php
Role: Example script
Content type: text/plain
Description: Example Script
Class: Database Queries
Abstraction for executing database queries
Author: By
Last change:
Date: 19 years ago
Size: 2,309 bytes


Class file image Download

  * Get the corresponding ConnectionManager object w.r.t to database specified in DB_TYPE constant(DBTypes.php).
  * Factory Method. One can use their own connection object. I used here ConnectionManager Class to connect to the database.
  * You can find the ConnectionManager Class at the following url
$objConnectionClass = ConnectionManagerFactory::getInstanceOf(DB_TYPE);

 * Invoke the doConnection object to make a connection to the specified database

 * Get the connectionHandle (Base Class Method).
$conn = $objConnectionClass->getConnectionHandle();

 * Select the database.

$selquery = "select * from alumini order by firstname";

 * $edited = "F";
 * $selquery = "SELARTICLES"; //(Procedure name).
 * $params = array("@edited"=>array($edited=>SQLCHAR, false)); // (Procedure Parameters).
$params = null;

 * Get the corresponding DatabaseQueries object w.r.t to database specified in DB_TYPE constant(DBTypes.php).
 * Factory Method.

 * if $params in null it means the query is of type inline otherwise it is a procedure and provide the $params associative array
 * as follows:-
 * $params -- Associative array eg. array("@edited"=>array($edited=>SQLCHAR, false));
 * where -- @edited is input/output paramter,
 * -- $edited is the value of Input Parameter @edited,
 * -- SQLCHAR is a the MSSQL Constant for CHAR column type,
 * -- false indicates @edited is not an output parameter.
$objDatabaseClass = DatabaseQueriesFactory::getInstanceOf($selquery, $conn, $params, DB_TYPE);

 * Call the executeQuery method.
"Cannot query");

/* $result = your resultset fetched from database by calling base class method getResultSet(). */

$result = $objDatabaseClass->getResultSet();
$row = $objDatabaseClass->getResultArray();
 * get the number of rows in a result set.
$rowcount = $objDatabaseClass->getNumRows();