|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2020-12-01 16:19 UTC] cmb@php.net
-Status: Open
+Status: Verified
-Package: Documentation problem
+Package: Variables related
-Assigned To:
+Assigned To: cmb
[2020-12-01 16:19 UTC] cmb@php.net
[2020-12-01 16:22 UTC] cmb@php.net
[2020-12-01 16:24 UTC] phpdocbot@php.net
[2020-12-01 16:24 UTC] phpdocbot@php.net
-Status: Verified
+Status: Closed
[2020-12-01 16:35 UTC] goran_zarkovic at zoho dot com
[2020-12-02 00:25 UTC] mumumu@php.net
[2020-12-02 00:30 UTC] phpdocbot@php.net
[2020-12-30 11:58 UTC] nikic@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 14:00:01 2025 UTC |
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.. */ } } ?>