juanecabellob
juanecabellob

Reputation: 454

Validating MySQL queries on php

Is it possible to get the query that it's being tried to be executed on PHP?

Here is the code i'm trying:

public static function executeInsertQuery($sqlQuery)
{
    $dbTable = mysql_query($sqlQuery, self::$_dbLink);

    if($dbTable === false){
        Models_Error::throwException("Connection to table failed.", 'database');
    }

    return null;
}

How can I validate that to be always an Insert into query?

Upvotes: 0

Views: 36

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324630

Don't rely on being passed a query.

In my current project, if I want to insert something, it looks like this:

DB::insert("tablename",array(
    "column" => "value",
    "col2"   => "val2",
    "foo"    => "bar"
));

This is then translated into a proper query (using PDO in this case, but that doesn't matter here)

Upvotes: 1

Related Questions