你必须创建一个唯一的ID,
3解决方案:
如果您使用MySQL为您自动生成ID(通过 AUTO_INCREMENT 列),那么为什么不向MySQL询问它给新行的ID $mysqli->insert_id() ?
AUTO_INCREMENT
$mysqli->insert_id()
例:
$result = $mysqli->query("insert into products set name='best product ever'"); if ($result === TRUE) { // put it into memcached $key = 'product_' . $mysqli->insert_id(); $product = array('id' => $id, 'name' => $name); $memcache->set($key, $product); }