ZF-5546: CLONE -CLONE -Zend_Db->query() silently dies after I try to insert text with length about 10 kilobytes. I'm using ZF 1.5.2 on Unix. I don't observe this problem on the same version on Windows

Description

by inserting an large text (greater than 5484 chars in ut8 charset, we uses "a's" as test character) into a database field Zend_Db_Statement causes an Apache segmentation fault the script dies in line 187 of Zend_Db_Statement without any exception to be caught

    // remove 'foo\'bar'
    $sql = preg_replace("/$q($qe|[^$q])*$q/", '', $sql);

We are using php 5.4.2 and apache 2.0 and apache 2.2 versions, and all versions are affected even if we use Zend Core php

Comments

Hi,

I have the same problem, I have create a class to store html content at mysql. I can't store more than 5484 chars at utf-8 and i am getting back white screen with no errors. The only thing i can see is at the error log at apache (segmentation fault(11)). I am getting this error only at linux not on windows and i have test it on 3 linux servers with the same results.

I have try this at many php versions and nothing happen. Please Help!!!

a part of my class...

$this->dbconnect();
        try {

                $sql = "INSERT INTO categories
                                         (catID,
                                          catTitle,
                                          lang,
                                          catDescription,
                                          catContent,
                                          catKeywords,
                                          catGoogleDesc,
                                          catOrder,
                                          catActive,
                                          catHomeActive,
                                          catHomeSection,
                                          catOpenActive,
                                          catHasContents
                                          )
                                  VALUES (
                                          ".$this->lastID.",
                                          '".$titlos."',
                                          ".$lang.",
                                          '".$description."',
                                          '".$fullcontent."',
                                          '".$googleKeywords."',
                                          '".$googleDesc."',
                                          ".$order.",
                                          ".$active.",
                                          ".$home_active.",
                                          ".$home_section.",
                                          ".$childs.",
                                          ".$has_contents."
                                          )";


                $this->db->query($sql);
            }
            $this->db->commit();
        } catch (Exception $e) {
            $this->db->rollBack();
            $this->db->delete('cat_tree', 'catID ='.$this->lastID);
            $this->error = true;
            $this->errorMessage = $e->getMessage();
            cal_public_baseFunctions::logErrors('Query Exception when i try to Add new Page :: storePages.php Class'.$e->getMessage());
            cal_public_baseFunctions::logErrors('Query Exception when i try to Add new Page :: Query '.$sql);
        }


    $this->dbclose();

Is that a 64 bit machine?

Also, you could try using the adapter insert method with placeholders, instead of crafting the query yourself:


$dbAdapter->insert('categories', array(
  'catID' => $this->lastID,
  'catTitle' => $titlos,
  ...
));

This would then only quote the sql statement, and bind the parameters afterwards. Let me know if that helps.

Thanks that solve my problem!!!

Also if you want to avoid this way you can just execute the query like this.

$sql ="Insert into categories...."; $adapter->getConnection()->exec($sql);

This is a known issue with preg_* functions on 64bit platforms. The workaround is to use the adapter with bound parameters instead of passing large unbound queries into the query() method.

And yes, by passing the adapter itself is definitely an option, but would result in decreasing the inherit benefits of using Zend_Db in the first place.

Thanks!