The insert operation using pdo to execute sql is miraculous.

  ios, question

图片描述

This command was executed in the onMessage callback function of php’s swoole websocket server, and the contents in the database did not completely conform to the sql specification.

The following is DDL for this table

CREATE TABLE `gobang_rooms` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `black_uid` int(10) unsigned DEFAULT NULL,
 `black _ seconds`medical (5) unsigned default null comment 'black seconds',
 `white_uid` int(10) unsigned DEFAULT NULL,
 `white_seconds` mediumint(5) unsigned DEFAULT NULL,
 `last_player` tinyint(3) unsigned DEFAULT NULL,
 `create_time` int(10) unsigned DEFAULT NULL,
 PRIMARY KEY (`id`)
 ) ENGINE=MEMORY AUTO_INCREMENT=11 DEFAULT CHARSET=utf8;

The following is the implementation of the update function

function update($sql, $params) {
 // var_dump($params);
 $pdo = new PDO(dsn, user, pass);
 $stmt = $pdo->prepare($sql);
 foreach ($params as $key => $value) {
 $stmt->bindParam($key plus 1, $value);
 bracket
 return $stmt->execute();
 bracket

This update function has been executed normally elsewhere, and there is a problem with its execution. The result does not match the value passed in by the statement. What is this?

BindParam should be used with caution in circulating inside. Please look at the manual the function prototype.
clipboard.png
As you can see, the second parameter is the reference, that is, the parameter you passed, and the previous value will become the value of the last parameter passed.

What you bind in the picture will naturally become 123456.last_playerIt will overflow, so it is 255.

Bird elder brother’s blog post inside mentioned this problem:http://www.laruence.com/2012/ …