我在将表从 MySQL 填充到另一个 MySQL 表时遇到问题 我从一张表中读取它,然后就可以了 当像奥布莱恩这样的姓氏 当我更新另一个表时,除了 O' Brian 或任何带有 ' 的名字或姓氏之外,所有内容都会通过 PHP 更新 好的,这是完整的代码
$STH2 = $this->run_query("SELECT `member_id`,`first_name`,`last_name` FROM `member_data` WHERE `member_id` = '".$evi."'");
$foundme=0;
while ($rowtop = $STH2->fetch())
{
$foundme++;
$first_name = $rowtop['first_name'];
$last_name= $rowtop['last_name'];
}
$q = $this->update("
UPDATE `users`
SET
`first_name` = '".$first_name."',
`last_name` = '".$last_name."',
最佳答案
好吧,如果你使用 PDO 试试这个:
$bdd = /* your database connexion */
$sql = "UPDATE `user`
SET `first_name` = :first_name, `last_name` = :last_name
WHERE `member_id` = 2001;";
$req = $bdd->prepare($sql);
$req->bindParam(':first_name', $first_name);
$req->bindParam(':last_name', $last_name);
$req->execute();
如果您不使用 PDO,语法可能会有所不同,但逻辑应该是相同的:
- 使用一些“参数”创建查询,此处为
:first_name
和:last_name
- 准备您的查询
- 将参数与实际值绑定(bind),此处为
$first_name
和$last_name
- 然后执行查询
这是你要找的吗?
关于php - 更新表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50627975/