Object Oriented MySQL Statements, PHP

So far i have got the code below which works lovely when trying an update, delete or select statement. However I run into problems when I try to use an insert. If someone could point me in the correct direction i would be grateful.

private function escape($value)
        $value = stripslashes($value);
    return mysql_real_escape_string($value, $this->dbConn);

 * Handles connection to the database.
 * Die functions are used to catch any errors.
public function connect($dbHost, $dbName, $dbUser, $dbPass)
    $this->dbConn = mysql_connect(
    ) or die(mysql_error());
    mysql_select_db($dbName, $this->dbConn) or die(mysql_error());

 * Loads a raw SQL string into the object $dbSql variable
public function prep($sql)
    $this->dbSql = $sql;

 * Load bound hooks and values into object variable
public function bind($hook, $value)
    $this->dbBind[$hook] = $this->escape($value);


 * Runs the SQL string in $dbSql object variable
public function run()
    $sql = $this->dbSql;
        foreach($this->dbBind as $hook => $value)
            $sql = str_replace($hook, "'" . $value . "'", $sql);  
    $this->dbQuery = mysql_query($sql) or die(mysql_error());
    $this->dbBind = array();
    return $this->numRows();

    // Load SQL statment into object
$MyDB->prep("INSERT INTO `demo` (`id`, `name`, `score`, `dept`, `date`) VALUES '1','James Kablammo', '1205550', 'Marketing', '$date'");
// Bind a value to our :id hook
// Produces: SELECT * FROM demo_table WHERE id = '23'

// Run the query


It may help to start with using valid insert statements.

VALUES ( a , b , c )


VALUES a, b , c 

Additionally, why the dickens are you combining a perpared insert with string substituion?

you mean

$q->prep("blah blah blah VALUES ( :date , etc etc ) " ); $q->bind(":date", $date );

or something along those lines. using both techniques is just nonsensical.

You should probably wrap the values() in parens too, like:

$MyDB->prep("INSERT INTO `demo` (`id`, `name`, `score`, `dept`, `date`) VALUES ('1','James Kablammo', '1205550', 'Marketing', '$date'"));

Need Your Help

Objective-C passing NSError pointer to NSFileManager within custom method

objective-c pointers nsfilemanager nserror

I have a method that uses ARC and takes an NSError pointer and I pass that into the contentsOfDirectoryAtPath:error: method of NSFileManager like so:

How to pass an array to liquid filters on the fly?


I have tried the following without success: