|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-09-15 17:12 UTC] jaba at inbox dot lv
Description:
------------
I am developing on Windows XP but the application production version is supposed to be on Debian. Seems like debian MySQLi is not working properly. I can use mysqli_fetch_row or $result->fetch_row, but whenever I use $result->fetch_assoc() or mysqli_fetch_assoc($result) on the same result, the application crashes and I receive no output at all.
Reproduce code:
---------------
<?php
$mysqli = new mysqli("localhost", "vaipusr", "parolite", "vaipdb");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT * FROM acc_users";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
echo '<pre>';
print_r($row);
echo '</pre>';
}
$result->close();
}
$mysqli->close();
?>
Expected result:
----------------
string representation of associated arrays of table rows
Actual result:
--------------
nothing. application dies whenever you call mysqli_fetch_assoc
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 03:00:01 2025 UTC |
Not easily, no. I'm not set up for external users. If it would really help, I could try. I've done some more digging: In ext/mysqli/mysqli.c, there is the following code: line 653: if (fetchtype & MYSQLI_ASSOC) { fields = mysql_fetch_fields(result); } line 677: if (fetchtype & MYSQLI_ASSOC) { if (fetchtype & MYSQLI_NUM) { ZVAL_ADDREF(res); } add_assoc_zval(return_value, fields[i].name, res); } line 687: if (fetchtype & MYSQLI_ASSOC) { add_assoc_null(return_value, fields[i].name); } If I change the fields[i].name argument to "hello", the offending functions then work. I successfully used fetch_array with MYSQLI_BOTH, and $array['hello'] referred to the last element in the fetched array. It seems as though the call to mysql_fetch_fields (part of the MySQL API) is failing, which is not being detected by the PHP code. More soon...Gah. I think I've got as far as my abilities allow. Basically, if either add_assoc_zval or add_assoc_null are called with anything other than a static string, crash. Even: char *tmp; ... sprintf(tmp, "hello"); add_assoc_zval(return_value, tmp, res); fails, although: add_assoc_zval(return_value, "hello", res); does not, and $array['hello'] returns the first value as expected. There is no issue with the mysql_fetch_fields() function: the failure occurs even with that commented out. I've traced the code path down to _zend_hash_add_or_update(), but I don't know enough to see any problems on the way there. *********************************** #define add_assoc_zval(__arg, __key, __value) add_assoc_zval_ex(__arg, __key, strlen(__key)+1, __value) *********************************** ZEND_API int add_assoc_zval_ex(zval *arg, char *key, uint key_len, zval *value) { return zend_symtable_update(Z_ARRVAL_P(arg), key, key_len, (void *) &value, sizeof(zval *), NULL); } *********************************** static inline int zend_symtable_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDa taSize, void **pDest) \ { HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_update(ht, idx, pData, nDataSize, pDest)); return zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest); } *********************************** #define zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest) \ _zend_hash_add_or_update(ht, arKey, nKeyLength, pData, nDataSize, pDest, HASH_UPDATE ZEND_FILE_LINE_CC) ***********************************Yes. I have the same problem. Clean WindowsXP install with only the installer of MySQL, Apache and PHP: Faulting application httpd.exe, version 2.2.11.0, faulting module php_mysqli.dll, version 5.2.9.9, fault address 0x00002b6b. All result class methods work fine except the "fetch_*"; I get a result object, the num_rows and field_count return correct values, I can traverse the metadata and display the fieldnames, but whenever I try to access the actual value Apache crashes. This is the crashing (test) code: echo $pResult->field_count; for ($i = 0; $i < $pResult->field_count; $i++) { echo $pResult->fetch_field_direct($i)->name; } return $pResult->fetch_assoc(); If the last line is dummified all the fieldname being displayed and there is no crash. Naturally I tried several other method calls to get to the data.