Results 1 to 15 of 17

Thread: [RESOLVED] mysql_query is performing several queries instead of just one

Threaded View

  1. #1
    Join Date
    Aug 2007

    resolved [RESOLVED] mysql_query is performing several queries instead of just one

    Hi all,

    I have been writing my website and have ended up starting a sort of MVC (model-view-controller) framework, which has made lots of sense to write.
    The problem I have is in my basic model. When I want it to insert a new record, instead of inserting one row, it inserts about five, all with the same properties (except the IDs, which is dealt with by MySQL itself). I checked the SQL query, and it is correct. I tested it by writing it directly into PHPMyAdmin and it only inserted one row.

    The model's method looks like this:
    PHP Code:
    function insert() {
    $sql "INSERT INTO " $this->table "
    $this->fields as $attr) {
    $this->blacklisted($attr) && $attr != $this->primaryKey) {
    $sql .= $attr ", ";
    $sql substr_replace($sql"", -2);
    $sql .= ") VALUES (";
    $this->fields as $attr) {
    $this->blacklisted($attr) && $attr != $this->primaryKey) {
    $sql .= "'" $this->{$attr} . "', ";
    $sql substr_replace($sql"", -2);
    $sql .= ")";
    The connector class for the database has a query() method which looks as follows:
    PHP Code:
    function query($sql null) {
    $sql str_replace(array("\"""\\"), array("'"""), $sql);
    $this->result mysql_query($sql) or $this->error("Unable to query database: " mysql_error($this->con) . ".");
    The SQL produced (using die($sql)) looks like this:

    INSERT INTO artworks (name, date, modified, type, category, collection, comment, public, keywords) VALUES ('test1', '2009-08-12', '2009-08-12', '1', '', '', 'This is a test.', '', 'test, first')
    This really is quite confusing, any help would be much appreciated.
    Last edited by blue-eye-labs; 08-11-2009 at 08:25 PM. Reason: little typo

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles