Jenk wrote:None of my details are ever kept within the class. Simply because I use the same class on many applications.
I use my machine and my database for developing applications for clients, with my classes, so the login details will differ.
All configurable items are kept in a configurations file or medium (table for example).
Ease of maintenance..
But.. all you would have to do is simply change the login credentials in the class for each project. Seems like storing them somewhere else would take away from the ease of maitenance?
Sorry, I'm just a bit confused
Also, it seems like while I'm writing this I'm just giving different names to the php functions. The reason I wanted to write this is to cut down on always typing out queries and other db functions the long way, to save some typing.. and to experience dealing with objects.
So I suppose it is a "wrapper" if that's what it's called. Can someone tell me the purpose of such a script, other than to cut down on coding?
Perhaps it is to get a solid class and reduce the chance of coding errors? To have something to transport from project to project?
Seems to me if I start getting used to a class that I write (such as this db class), I will start forgetting the real php functions!
Here's what I got so far:
Code: Select all
<?php
//temp
ini_set("display_errors","On");
error_reporting(E_ALL);
/*
* MySQL Database Class
*/
class db
{
var $host = 'localhost';
var $user = 'user';
var $pass = 'pass';
var $db_name = 'db_name';
var $resource;
//connect to mysql server
function connect()
{
if($this->resource = mysql_connect($this->host,$this->user,$this->pass))
{
return true;
} else
{
return false;
}
}
//select database
function select_db()
{
return mysql_select_db($this->db_name,$this->resource);
}
//query the database
function query($sql)
{
return mysql_query($sql);
}
//fetch array from result set, defaults to MYSQL_ASSOC
function fetch($result,$type=MYSQL_ASSOC)
{
return mysql_fetch_array($result,$type);
}
//frees result set from mysql memory
function free_result($result)
{
mysql_free_result($result);
}
}
?>
[edit] I suppose I went from a simple question, to... something else, didn't I?
