Results 1 to 10 of 42
Threaded View
-
29th Jul 2012, 04:00 PM #36MemberPHP Code:
<?php
class Database
{
var $con;
var $sel;
var $res;
var $assoc;
var $escape;
var $array;
var $row;
function connect()
{
$this->con = mysql_connect("localhost", "host", "") or die(mysql_error());
$this->sel = mysql_select_db("test") or die(mysql_error());
}
function close()
{
if (isset($this->connect)) {
mysql_close($this->connect());
unset($this->connect);
}
}
function query($sql)
{
$this->res = mysql_query($sql) or die(mysql_error());
return $this;
}
function fetch($type)
{
switch ($type) {
case 1:
$this->assoc = mysql_fetch_assoc($this->res);
return $this;
break;
case 2:
$this->array = mysql_fetch_array($this->res);
return $this;
break;
case 3:
$this->row = mysql_fetch_row($this->res);
return $this;
break;
}
}
function escape($escape)
{
$this->escape = mysql_real_escape_string($escape);
return $this->escape;
}
function get($num, $col)
{
switch ($num) {
case 1:
return ($this->assoc[$col]);
break;
case 2:
return ($this->array[$col]);
break;
case 3:
return ($this->row[$col]);
break;
}
}
}
//initiate the database class
$database = new Database();
//connect to the database
$database->connect();
//run a query
$database->query("SELECT * FROM table");
//runs, chooses the type of query, and what collumn
$database->query()->fetch(1)->get(1,'username');
//close the database
$database->close();
?>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Plz Help To Add A Php Snippet Into My DLE Index !
By JoomlaZ in forum Web Development AreaReplies: 0Last Post: 7th Jul 2011, 01:18 PM -
[C#] Tiny Web Server (snippet)
By Hyperz in forum Web Development AreaReplies: 6Last Post: 24th Jun 2010, 01:19 PM -
Image Upload in php. Code snippet #2
By SplitIce in forum Tutorials and GuidesReplies: 5Last Post: 31st Oct 2009, 07:40 AM -
See real OOP (Snippet from Litewarez V2) Webmasters CP
By litewarez in forum Tutorials and GuidesReplies: 21Last Post: 19th Sep 2009, 03:59 PM -
A Snippet from my latest project
By litewarez in forum Tutorials and GuidesReplies: 19Last Post: 21st Jun 2009, 05:17 PM
themaCreator - create posts from...
Version 3.55 released. Open older version (or...