Doc #80453 [Opn->Ver]: Documentation example error

From: Date: Tue, 01 Dec 2020 16:19:29 +0000
Subject: Doc #80453 [Opn->Ver]: Documentation example error
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18172@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80453&edit=1 ID: 80453 Updated by: cmb@php.net Reported by: goran_zarkovic at zoho dot com Summary: Documentation example error -Status: Open +Status: Verified Type: Documentation Problem -Package: Documentation problem +Package: Variables related PHP Version: Irrelevant -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Thanks for reporting in the bugtracker! :) Previous Comments: ------------------------------------------------------------------------ [2020-12-01 12:16:35] goran_zarkovic at zoho dot com 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 this bug report at https://bugs.php.net/bug.php?id=80453&edit=1

« previous php.doc.bugs (#18172) next »