Viewing topic:MySQL Class
Page: 1
Topic post 03-10-2007 - 11:37
Graham

Quote quote
[code=php]class sqlObject {

var $server;
var $username;
var $password;
var $database;

function connect($server, $username, $password, $database) {
$sql_con = @mysql_connect($server, $username, $password);
$db_sel = @mysql_select_db($database, $sql_con);
if (!$sql_con) die("Could not connect to the database!";
if (!$db_sel) die("Could not select the database!";
}

function query($query) {
$query = @mysql_query($query);
if (!$query) die("Could not complete query: ".htmlentities($query));
}
}[/code]
Topic post 03-10-2007 - 11:43
Graham

Quote quote
The above was to do with the tutorial but this is what I would use for a pastebin.

Code:

1

2
    var $server;
3
    var $username;
4
    var $password;
5
    var $database;
6
    
7
    function connect($server, $username, $password, $database) {
8
        $sql_con = @mysql_connect($server, $username, $password);
9
        $db_sel = @mysql_select_db($database, $sql_con);
10
        if (!$sql_con) die("Could not connect to the database!");
11
        if (!$db_sel) die("Could not select the database!");
12
    }
13
    
14
    function insert($name, $paste, $ip, $timestamp, $lang, $private) {
15
        $query = @mysql_query("INSERT INTO pastes VALUES ('', '$name', '$paste', '$ip', '$timestamp', '$lang', '$private')");
16
        if (!$query) die("Could not insert query to database!");
17
    }
18
    
19
    function retrieve($id) {
20
        $results = @mysql_query("SELECT * FROM pastes WHERE ID = '$id'" ;
21
        $array =  @mysql_fetch_assoc($results);
22
        if (!$array) die("Could not retrieve entry! Either an error occured or the desired ID doesn't exist.");
23
        return $array;
24
    }
Topic post 03-10-2007 - 13:48
Jim

Quote quote
Looks pretty good, you might want to add addslashes and stripslashes to the query's

©Copyrights Combined Minds. All rights reserved 2006 - 2009 : Disclaimer