Connection Reset on MySQL query

Posted by sunwukung on Server Fault See other posts from Server Fault or by sunwukung
Published on 2010-05-21T11:05:45Z Indexed on 2010/05/21 11:10 UTC
Read the original article Hit count: 655

Filed under:
|
|

OK, I'm flummoxed.(i've asked this question over on Stack too - but I need to get it fixed so I'm asking here too - any help is GREATLY appreciated) I'm trying to execute a query on a database (locally) and I keep getting a connection reset error. I've been using the method below in a generic DAO class to build a query string and pass to Zend_Db API.

public function insert($params) {
    $loop = false;
    $keys = $values = '';
    foreach($params as $k => $v){
        if($loop == true){
            $keys   .= ',';
            $values .= ',';
        }
        $keys   .= $this->db->quoteIdentifier($k);
        $values .= $this->db->quote($v);
        $loop = true;
    }

    $sql = "INSERT INTO " . $this->table_name . " ($keys) VALUES ($values)";

    //formatResult returns an array of info regarding the status and any result sets of the query
    //I've commented that method call out anyway, so I don't think it's that
    try {
        $this->db->query($sql);
        return $this->formatResult(array(
                true,
                'New record inserted into: '.$this->table_name
        ));
    }catch(PDOException $e) {
        return $this->formatResult($e);
    }
}

So far, this has worked fine - the errors have been occurring since we generated new tables to record user input. The insert string looks like this:

INSERT INTO tablename(`id`,`title`,`summary`,`description`,`keywords`,`type_id`,`categories`) VALUES ('5539','Sample Title','Sample content','
\'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In et pellentesque mauris. Curabitur hendrerit, leo id ultrices pellentesque, est purus mattis ligula, vitae imperdiet neque ligula bibendum sapien. Curabitur aliquet nisi et odio pharetra tincidunt. Phasellus sed iaculis nisl. Fusce commodo mauris et purus vehicula dictum. Nulla feugiat molestie accumsan. Donec fermentum libero in risus tempus elementum aliquam et magna. Fusce vitae sem metus. Aenean commodo pharetra risus, nec pellentesque augue ullamcorper nec. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nullam vel elit libero. Vestibulum in turpis nunc.\'','this,is,a,sample,array',1,'category title') 

Here are the parameters it's getting before assembling the query (var_dump):

array
    'id' => string '1' (length=4)
    'title' => string 'Sample Title' (length=12)
    'summary' => string 'Sample content' (length=14)
    'description' => string '<p>'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In et pellentesque mauris. Curabitur hendrerit, leo id ultrices pellentesque, est purus mattis ligula, vitae imperdiet neque ligula bibendum sapien. Curabitur aliquet nisi et odio pharetra tincidunt. Phasellus sed iaculis nisl. Fusce commodo mauris et purus vehicula dictum. Nulla feugiat molestie accumsan. Donec fermentum libero in risus tempus elementum aliquam et magna. Fusce vitae sem metus. Aenean commodo pharetra risus, nec pellentesque augue'... (length=677)
    'keywords' => string 'this,is,a,sample,array' (length=22)
    'type_id' => int 1
    'categories' => string 'category title' (length=43)

The next port of call was checking the limits on the table, since it seems to insert if the length of "description" is around the 300 mark (it varies between 310 - 330). The field limit is set to VARCHAR(1500) and the validation on this field won't allow anything past bigger than 1200 with HTML, 800 without.

The real kicker is that if I take this sql string and execute it via the command line, it works fine - so I can't for the life of me figure out what's wrong.

I've tried extending the server parameters i.e. http://stackoverflow.com/questions/1964554/unexpected-connection-reset-a-php-or-an-apache-issue

So, in a nutshell, I'm stumped. Any ideas?

© Server Fault or respective owner

Connection Reset on MySQL query

Posted by sunwukung on Stack Overflow See other posts from Stack Overflow or by sunwukung
Published on 2010-05-21T09:35:41Z Indexed on 2010/05/21 9:40 UTC
Read the original article Hit count: 655

Filed under:
|
|

OK, I'm flummoxed. I'm trying to execute a query on a database (locally) and I keep getting a connection reset error. I've been using the method below in a generic DAO class to build a query string and pass to Zend_Db API.

public function insert($params) {
    $loop = false;
    $keys = $values = '';
    foreach($params as $k => $v){
        if($loop == true){
            $keys   .= ',';
            $values .= ',';
        }
        $keys   .= $this->db->quoteIdentifier($k);
        $values .= $this->db->quote($v);
        $loop = true;
    }

    $sql = "INSERT INTO " . $this->table_name . " ($keys) VALUES ($values)";

    //formatResult returns an array of info regarding the status and any result sets of the query
    //I've commented that method call out anyway, so I don't think it's that
    try {
        $this->db->query($sql);
        return $this->formatResult(array(
                true,
                'New record inserted into: '.$this->table_name
        ));
    }catch(PDOException $e) {
        return $this->formatResult($e);
    }
}

So far, this has worked fine - the errors have been occurring since we generated new tables to record user input. The insert string looks like this:

INSERT INTO tablename(`id`,`title`,`summary`,`description`,`keywords`,`type_id`,`categories`) VALUES ('5539','Sample Title','Sample content','
\'Lorem ipsum dolor sit amet, consectetur adipiscing elit. In et pellentesque mauris. Curabitur hendrerit, leo id ultrices pellentesque, est purus mattis ligula, vitae imperdiet neque ligula bibendum sapien. Curabitur aliquet nisi et odio pharetra tincidunt. Phasellus sed iaculis nisl. Fusce commodo mauris et purus vehicula dictum. Nulla feugiat molestie accumsan. Donec fermentum libero in risus tempus elementum aliquam et magna. Fusce vitae sem metus. Aenean commodo pharetra risus, nec pellentesque augue ullamcorper nec. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nullam vel elit libero. Vestibulum in turpis nunc.\'','this,is,a,sample,array',1,'category title') 

You'll probably notice the big chunk of whitespace before the Lorem Ipsum string. The description field is being populated from a TinyMCE textarea - I'm guessing it's chucking in some line returns, so I've tried stripping those out. However, even if I disable the TinyMCE field, the reset error still occurs.

The next port of call was checking the limits on the table, since it seems to insert if the length of "description" is around the 300 mark (it varies between 310 - 330). The field limit is set to VARCHAR(1500) and the validation on this field won't allow anything past bigger than 1200 with HTML, 800 without.

The real kicker is that if I take this sql string and execute it via the command line, it works fine - so I can't for the life of me figure out what's wrong.

So, in a nutshell, I'm stumped. Any ideas?

© Stack Overflow or respective owner

Related posts about mysql

Related posts about connection-reset