如何使用PHP代码更新数据库表?

时间:2016-12-19 09:53:19

标签: php mysql

我有以下PHP,它会将数据从excel插入数据库,但它不会更新它。

请指导我如何完成它?如果我改变了什么,那么它也会更新到数据库表行。

foreach($dataArr as $val){
$query = $db->query("INSERT INTO employees SET fname = '" . $db->escape($val['1']) . "', lname = '" . $db->escape($val['2']) . "', email = '" . $db->escape($val['3']) . "', phone = '" . $db->escape($val['4']) . "', company = '" . $db->escape($val['5']) . "'");
}

提前致谢

2 个答案:

答案 0 :(得分:1)

替换

INSERT INTO employees 

UPDATE employees 

<强> Update Syntax

UPDATE [LOW_PRIORITY] [IGNORE] table_references
SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
[WHERE where_condition]

答案 1 :(得分:0)

不插入使用更新

$query = $db->query("Update employees SET fname = '" . $db->escape($val['1']) . "', lname = '" . $db->escape($val['2']) . "', email = '" . $db->escape($val['3']) . "', phone = '" . $db->escape($val['4']) . "', company = '" . $db->escape($val['5']) . "'" [WHERE where_condition]);
}