Doc #80453 [NEW]: Documentation example error
| From: | goran_zarkovic at zoho dot com | Date: | Tue, 01 Dec 2020 12:16:36 +0000 |
| Subject: | Doc #80453 [NEW]: Documentation example error | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-18169@lists.php.net to get a copy of this message | ||
From: goran_zarkovic at zoho dot com
Operating system:
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Documentation example error
Description:
------------
There seems to be an error in serialize() function #1 Example:
<?php
// $session_data contains a multi-dimensional array with session
// information for the current user. We use serialize() to store
// it in a database at the end of the request.
$conn = odbc_connect("webdb", "php", "chicken");
$stmt = odbc_prepare($conn,
"UPDATE sessions SET data = ? WHERE id = ?");
$sqldata = array (serialize($session_data), $_SERVER['PHP_AUTH_USER']);
if (!odbc_execute($stmt, $sqldata)) {
$stmt = odbc_prepare($conn,
"INSERT INTO sessions (id, data) VALUES(?, ?)");
if (!odbc_execute($stmt, $sqldata)) {
/* Something went wrong.. */
}
}
?>
SQL INSERT will result in data and id columns content inverted: $sqldata
array contains session_data and id, so positional data binding will have
effect of column id containing session_data, and column data containing
PHP_AUTH_USER.
Proposed correction:
<?php
// $session_data contains a multi-dimensional array with session
// information for the current user. We use serialize() to store
// it in a database at the end of the request.
$conn = odbc_connect("webdb", "php", "chicken");
$stmt = odbc_prepare($conn,
"UPDATE sessions SET data = ? WHERE id = ?");
$sqldata = array (serialize($session_data), $_SERVER['PHP_AUTH_USER']);
if (!odbc_execute($stmt, $sqldata)) {
$stmt = odbc_prepare($conn,
"INSERT INTO sessions (id, data) VALUES(?, ?)");
$sqldata = array ($_SERVER['PHP_AUTH_USER'], serialize($session_data)
);
if (!odbc_execute($stmt, $sqldata)) {
/* Something went wrong.. */
}
}
?>
--
Edit bug report at https://bugs.php.net/bug.php?id=80453&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80453&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80453&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80453&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80453&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80453&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80453&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80453&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80453&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80453&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80453&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80453&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80453&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80453&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80453&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80453&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80453&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80453&r=mysqlcfg