Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP mysql为以后的更新选择语句的更快方法?_Php_Mysql_Sql_Select - Fatal编程技术网

PHP mysql为以后的更新选择语句的更快方法?

PHP mysql为以后的更新选择语句的更快方法?,php,mysql,sql,select,Php,Mysql,Sql,Select,我有以下代码: $result = mysqli_prepare($con, "select pass from signin where domain = ? and username = ? for update"); //Check if record is available //Do some checking here that pass is correct //Then I need a new hash for the password so I use (after maki

我有以下代码:

$result = mysqli_prepare($con, "select pass from signin where domain = ? and username = ? for update");
//Check if record is available
//Do some checking here that pass is correct
//Then I need a new hash for the password so I use (after making the new hash)
$resultnew = mysqli_prepare($con, "update signin set pass = ? where domain = ? and username = ?");
所以这里一切都很好

但我不喜欢的是,update语句必须再次查找带有域和密码的记录,因为我已经有了第一个select语句中的记录,这浪费了时间

有没有办法在执行检查后直接从第一个select语句更新pass?简言之,是否存在类似的情况,或者我应该坚持我正在做的事情:

password = select pass from signin where domain = ? and username = ?;
//checking and making new hash
set password = $newhash

您应该为数据库的每一行使用唯一的ID。这应该是一个索引,最好启用自动递增。此类表格的一个示例:

CREATE TABLE IF NOT EXISTS `my_table` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
   <other columns>
   PRIMARY KEY (`ID`),
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

由于ID是您的主索引,这将非常快。

假设您有ID或类似的索引列,使用它进行更新查询。我一直在努力考虑使用select语句进行更新,我完全忘记了唯一的ID。@1…并且,@Rami,您可能想了解数据库规范化:啊,是的,我完全忘记了我已经创建的唯一ID。那应该是最快的方法。谢谢
UPDATE signin 
SET pass = ? 
WHERE id = ?