WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP Object Example of the Perl DBI with MySQL
Categories : PHP, PHP Classes, MySQL, Databases, Perl Update Picture
Rob Curts
Date : Jul 30th 2000
Grade : 2 of 5 (graded 3 times)
Viewed : 14957
File : PhpDBI.inc
Images : No Images for this code example.
Search : More code by Rob Curts
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

This is an example of a DBI object with PHP. This is a functional object that works well with
MySQL. This can be altered to work with ODBC, Oracle, Postgres...

You will have to change the values of the object properties and fill in the proper username,
password, etc.

<?

/********************************************************
* PHP DBI Object
*
* This object acts like Perls DBI object. To use this
* object just require this object file, and then perform
* the following steps with your statements:
*
* require 'PhpDBI.inc';
* $db = new PhpDBI;
* $sql = "select aField from tableName ";
* $db->connect();
* $db->prepare($sql);
* $db->execute($sql);
* while ($returnVar = mysql_fetch_array($db->sth)) {
* DO_SOMETHING_WITH: $returnVar['aField'];
* }
* $db->disconnect();
********************************************************/

class PhpDBI {
/* DB OBJECT PROPERTIES */
var $dbh = false; // database handler
var $sth; // statement handler (our cursor)
var $user = "USERNAME"; // db username
var $pass = "PASSWORD"; // db password
var $host = "HOSTNAME"; // hostname for database (usually localhost)
var $db = "DATABASE"; // name of database
var $sql; // sql statement

/* METHOD: Connect to Database
* returns: true on a good connection, false otherwise */
function connect() {
$this->dbh = false;
$this->dbh = mysql_connect($this->host,$this->user,$this->pass);
mysql_select_db($this->db,$this->dbh);
if (!$this->dbh)
return false;
else
return $dbh;
}

/* METHOD: Check Database connection
* returns: database handler */
function check() {
return $this->dbh;
}

/* METHOD: Disconnect from database */
function disconnect() {
mysql_close($this->dbh);
$this->dbh = false;
}

/* METHOD: Load SQL statement into object */
function prepare($sql) {
$this->sql = $sql;
}

/* METHOD: Execute a random SQL Query
* expects: SQL String
* boolean $ret ( 1 for needing a return value, 0 for no return) */
function execute($sql) {
if ($this->check())
$this->sth = mysql_query($this->sql,$this->dbh);
}
}

?>



A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP
Simple database class
Categories : PHP, PHP Classes, MySQL, Databases
Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible
Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server
Powerful php/mysql Pagination for up to 6 URL Params
Categories : PHP, PHP Classes, Databases, MySQL, Navigation
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
Simple Mini Poll class library (SimPoll)
Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
[PHP5] aDB PDO LIKE Database Abstraction. Switch easily from one db server to another, strong errors management, manage transactions, queries preparation and more.
Categories : PHP, PHP Classes, Databases, MS SQL Server, MySQL
Password reminder
Categories : PHP, PHP Classes, Databases, MySQL, Mail
Online Automatic Class Generator for MySQL Tables
Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL
Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides
MySQL Connection/Query Class
Categories : Databases, MySQL, PHP, PHP Classes
phpFormGenerator for Dynamic Form Generation from MySQL
Categories : PHP, PHP Classes, MySQL, Databases, HTML and PHP
MySQL Class to ease Database connectivity
Categories : MySQL, PHP Classes, Databases, PHP