Search

Thursday 21 January 2010

Simple php database helper function

the following PHP class has been written to simplify database usage in PHP and make it more of an object oriented way of performing tasks.

This function will also allow you to use mysql from php without having to bother about the php functions for SQL.

You can download the .php file from http://nasaralla.googlecode.com/files/database.php

The following example shows how you could use this file:
________________________________________
//Include the file
include("database.php");
//provide parameters for connecting to the MySQL server
//the functions needs to be provided with the host, database_name, username and password in //order
$db = new DBConnect('localhost', 'jobdb','root','');
$con = $db->setDB();
//then simply run any query using the following function
$result = $db->makeQuery("select * from candidate;");
//and finally terminate connection with server
$db->closeConnection($con);

________________________________________

Yes you are not totally independent of writing queries in this version which I hope to add in the future but this does gives you the flexibility of 'selecting' with a wider and more complex queries.

No comments:

Post a Comment