MySQL OOP Database Script
May 28, 2008 | 2 comments | 3 Pages | Developed by David Rosthorn
Introduction
Monday, June 30, 2008 : UPDATED TO VERSION 1.05 Stable - from VERSION 1.02
This MySQL OOP Database connection class was submitted by David Rosthorn and it makes MySQL queries more manageable by breaking down the key functions and features of the MySQL module found in all standard PHP installations and creates an environment that is a little faster to work with.
Notes from David Rosthorn regarding the Monday, June 30, 2008 Update to version 1.05:
rather than just setting a blank string as
"nothing" in the DB, it literally sets it as NULL like it should. The
only catch is that you HAVE to make sure you set up the tables to allow
nulls in the appropriate fields where nulls might occur so you can do a proper SQL query:
Usage Examples
Note: As of version 1.05 you may
now initiate multiple database instances with seperate database
crudentials. For example if you needed to connect to 2 completley different
databases from your script you would do so by initiating multiple
instances of the class, you would then use the new function "setup_db()" to load the new crudentials.
To initiate the class with new values for database connection add the following above all possible MySQL queries.
To initiate the class with the default values located in the script it self add the following above all possible MySQL queries.
To initiate more than one database connection you would do something like the example below, of course tailored to your needs.
SELECT() example
the select function allows you to make a SELECT * FROM query from your database.
INSERT() example
The insert function allows you to make an INSERT INTO query on your database.
UPDATE() example
The update function allows you to make an UPDATE `table` query on your database.
DELETE() example
The delete function lets your make a DELETE FROM query on your database.
COUNT() example
The count function works like the mysql_num_rows() function but its method is shortened down a bit.
· Credit: Developed by David Rosthorn - Click here to visit the website.
· Keywords: mysql, oop, database, tutorial
Could you show an example of using this class within a contorller file? like a real world example of how to display mysql data.
Thanks