Page 1 of 1

Apache crashes on `name` in the SQL

Posted: Wed Sep 19, 2007 6:33 am
by superdezign
I've had a few times where (locally) Apache would "crash" by a page refusing to load, and then an error window popping up saying that "Apache has encountered a problem..." However, each of these times, I found ways around it by refining my code. The only problem is that I'm now reaching one that makes absolutely no sense. ;_;

I build a query in order to populate my form elements using the databases. The function that I use for this looks like this:

Code: Select all

protected function populateFormElement(Vol_Form_Element_Multiple $pElement, $table, $nameColumn, $valueColumn, $orderBy = '', $condition = '')
{
    try {
        $this->__pSql->query("SELECT
                                  `" . $this->__pSql->escape($nameColumn) . "` AS `name`,
                                  `" . $this->__pSql->escape($valueColumn) . "` AS `value`
                              
                              FROM
                                  `" . $this->__pSql->escape($table) . "`"
                              . (!empty($condition) ? " WHERE  $condition" : '')
                              . (!empty($orderBy) ? " ORDER BY  $orderBy" : '')
                              . ";");
        while ($data = $this->__pSql->fetchObject()) {
            $pElement->addOption($data->name, $data->value);
        }
    } catch (Vol_Exception $e) {
        $pElement->addOption('-- Error --');
        
        // Save the error
        $this->log("There was an error populating a form element using the table, '$table,' name column, '$nameColumn,' and value column, '$valueColumn.'", self::LOG_ERROR);
    }
    
    return $pElement;
}
It works fine for all of these:

Code: Select all

$this->populateFormElement($pSystem, 'systems', 'name', 'id', '`id` ASC'); // `id` is in the table
$this->populateFormElement($pSystem, 'systems', 'name', 'id', '`abbr` ASC'); // `abbr` is in the table
$this->populateFormElement($pSystem, 'systems', 'name', 'id', '`value` ASC'); // `value` is not in the table, but an alias from the query
But Apache crashes on this:

Code: Select all

$this->populateFormElement($pSystem, 'systems', 'name', 'id', '`name` ASC'); // ?????
I'm stumped. Anyone know what may be happening?

Posted: Wed Sep 19, 2007 8:20 am
by maliskoleather
I'd almost bet that you're having an issue with your database. I assume you're not getting any database errors in your log?

Posted: Wed Sep 19, 2007 8:36 am
by superdezign
Nope. Just that Apache exited with "status 3221225477," then restarted.

What makes it weirder is that "`name` DESC" works, but not "`name` ASC." ;_;

Posted: Wed Sep 19, 2007 10:07 am
by feyd
What if you removed the requirements to use column aliases?

Posted: Wed Sep 19, 2007 10:43 am
by maliskoleather
is this on a postgres db?

Posted: Sun Sep 23, 2007 6:20 am
by superdezign
maliskoleather wrote:is this on a postgres db?
No.
feyd wrote:What if you removed the requirements to use column aliases?
Well, that didn't fix the problem, but it did help me to pinpoint exactly what was causing the problem. It's $data->value. Even if I omit the aliases and use $data->$valueColumn, I still end up with the server freezing, but once I get rid of it, it works fine. And it only occurs when using "`name` ASC" (so far). I've even tried fetching the data as a numerical array, and it crashes when I attempt to access the second index.


I've been playing around with it for a few hours and I've pinpointed the failure to actually being either when I create the output or when it attempts to echo the output. Apache is crashing when the "value" attribute of the <option> element is only 1 character long (including numbers less than 10), but it *only* happens when I use "`name` ASC." I also tried replacing the "value" attribute name, and every attribute name (valid or not) that is longer than 3 characters causes it to crash. So, so far it just seems like Apache gets angry with short strings while I'm using "`name` ASC." Why... I'm not sure.


The solution thus far is:

Code: Select all

if (is_numeric($data->value)) {
   $data->value = str_pad($data->value, 2, '0', STR_PAD_LEFT);
}
Should I just be happy with it...?

Posted: Sun Sep 23, 2007 8:46 am
by feyd
...and if you swap the "fetch object" bit for a standard array (associative or not, it doesn't matter in this context), what happens then?

Posted: Sun Sep 23, 2007 9:15 am
by superdezign
feyd wrote:...and if you swap the "fetch object" bit for a standard array (associative or not, it doesn't matter in this context), what happens then?
I mentioned trying the numerical array in my last post (and just tried the numerical, associative, and the regular fetch_array just in case) and it produces the same result. Strangely, whether I use the "value" as the value attribute or as the option label, the same thing happens. I can't seem to find any concrete consistency aside from the fact that it only occurs on "`name` ASC."

According to my searches on the internet, Apache on Windows is slightly glitchy. ;_;

Posted: Sun Sep 23, 2007 9:45 am
by feyd
Have you tried losing __pSQL entirely (going back to whatever native calls?)