We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27397
    • 8 Posts
    Hi,

    I’m using MODx 0.9.5 and I’m very glad about this software. Till now everything works very fine. But recently I’ve got a serious problem that I can’t solve myself.

    The problem:

    Inside a snippet I update a self created table. On development server the snippet works fine. On production server the snippet causes a php error on this part of the snippet-code:
    $query = 'UPDATE `tix__mob_ratesdata` SET'.
    			' `ratename`=\''.uml($_POST["ratename"]).'\','.
    			' `artnumber`=\''.$_POST["artnumber"].'\','.
    			' `networkid`=\''.$_POST["networkid"].'\','.
    			' `validto`=\''.$_POST["validto"].'\','.
    			' `validfrom`=\''.$_POST["validfrom"].'\','.
    			' `deeplink`=\''.$_POST["deeplink"].'\','.
    			' `mobiletype`=\''.$_POST["mobiletypeid"].'\','.
    			' `minpricemobile`=\''.str_replace(',', '.', $_POST["minpricemobile"]).'\','.
    			' `billtype`=\''.$_POST["billtype"].'\','.
    			' `contracttype`=\''.$contracttypestring.'\','.
    			' `contractterm`=\''.$_POST["contractterm"].'\','.
    			' `timingdevice`=\''.uml($_POST["timingdevice"]).'\','.
    			' `infolink`=\''.$_POST["infolink"].'\','.
    			' `minusesmsincl`=\''.$_POST["minusesmsincl"].'\','.
    			' `fixedprice`=\''.str_replace(',', '.', $_POST["fixedprice"]).'\','.
    			' `minuse`=\''.str_replace(',', '.', $_POST["minuse"]).'\','.
    			' `allinclminutes`=\''.$_POST["allinclminutes"].'\','.
    			' `owninclminutes`=\''.$_POST["owninclminutes"].'\','.
    			' `owninclminfixednet`=\''.$_POST["owninclminfixednet"].'\','.
    			' `priceonwayworkdayfixednetwork`=\''.str_replace(',', '.', $_POST["priceonwayworkdayfixednetwork"]).'\','.
    			' `priceonwayworkdayownnetwork`=\''.str_replace(',', '.', $_POST["priceonwayworkdayownnetwork"]).'\','.
    			' `priceonwayworkdayothernetworks`=\''.str_replace(',', '.', $_POST["priceonwayworkdayothernetworks"]).'\','.
    			' `rateremark`=\''.uml($_POST["rateremark"]).'\','.
    			' `rateonlineadvantage`=\''.uml($_POST["rateonlineadvantage"]).'\''.
    			' WHERE `providerid`='.$_POST["providerid"].' AND `id`='.$_POST["rateid"];
    	$dbresult = $modx->dbQuery($query);


    The php-error is all the time:
    PHP Fatal error: Out of memory (allocated 1016856576) (tried to allocate 335618727 bytes) in \manager\includes\document.parser.class.inc.php on line 1289

    The line 1289 in the document.parser is:
    $msg= mysql_escape_string($msg);


    I already tried to do:

    1.
    After several checks of the php.ini settings I used the php.ini (production) from the production server on my development server. The snippet works fine on development server although the php.ini is the same like on production server. So I believe php-settings can’t cause the error.

    2.
    When I decrease the number of table cells to update in the snippet, then the snippet is working on production server too.
    (So the workaround is to split the update command into several update commands and it is working. But this is not satisfying me).

    3.
    According to php.net ‘mysql_escape_string’ is old and should be replaced by mysql_real_escape_string’. Unfortunately I couldn’t try this till now because I would need to change this on the production server inside the document.parser. (Remember: On development server everything works fine). I’ll set up a backup-website on the production server soon and then I’ll try this there.


    Could anyone provide some additional ideas for help?


    Last but not least some environmental data of the production server:

    PHP Version 5.2.0
    MySQL Version 5.0.22
    Apache Version: 2.0.59
    Operating System: Windows NT 5.2 build 3790 (WIN2k3 SP2) but also didn’t work on SP1

    Client OS or Browser doesn’t matter to this error

    MODx Version 0.9.5
    No Changes made in MODx files
    No Plugins called

    On Development Server I’m using XAMPP 1.5.4 (Apache 2.2.3, PHP 5.1.6, MySQL 5.0.24a)
      • 25663 MODX Staff
      • 12,272 Posts
      Check to see if MySQL is running in strict mode on your production server. If so, disable that.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 27397
        • 8 Posts
        The problem is solved! The reason for the out of memory error was a misunderstanding (I don’t know how I should call it better) between php and MySQL or/and a mistake in MySQL table structure.

        The update command above is updating some columns of the type ’Tinyint’. The standard of these columns was not set to ’0’ in MySQL table structure.

        To collect data from the web I used a POST web form with <input type="checkbox" ...></input>. When these checkboxes on the web form are not checked, then the related $_POST variable is empty NOT 0 like I guessed. To fill the table cell of type Tinyint with an empty variable was not possible (of course) and caused the out of memory error.

        Solution:

        1.
        The error could be solved by adding the standard ’0’ in the table structure of respective columns.

        2.
        The update command of respective columns could be changed like this:

        Wrong
        'Update ... SET `colname` = \''.($_POST["celldataoftypetinyint"] .'\' WHERE ...';


        Right
        'Update ... SET `colname` = \''.($_POST["celldataoftypetinyint"] > 0 ? 1 : 0) .'\' WHERE ...';


        So the post variable will be set to 0 or 1 in any case (hopefully). I only dont understand why it works under XAMPP.

        Bye
          • 27397
          • 8 Posts
          Hi rthrash,

          you’re right. The server is running in sql-mode="STRICT_TRANS_TABLES, ...". XAMPP-MySQL is not. That might be the difference. Thanks for your help.