gpt4 book ai didi

php - 将数据从php插入数据库mysql表

转载 作者:行者123 更新时间:2023-11-28 23:47:44 26 4
gpt4 key购买 nike

我在将数据从 php 插入数据库时​​遇到问题。

文件是:Patient.php

表名是:patient_tbl

表格里面是:avatareducation

这里是插入代码:下面这段代码没有问题,'education'的值将被插入到表中

$sql = "INSERT INTO " . $this->_table;
$sql .= "education,";
$params = array(
urlencode($patient->getEducation()),
);
return $this->exec($sql, $params);
}

但现在这是我的问题,“头像”不插入表格

错误消息是:“无法准备查询。”

$sql = "INSERT INTO " . $this->_table;
$sql .= "education, avatar, ";
$params = array(
urlencode($patient->getEducation()),
urlencode($patient->getAvatar()),
);
return $this->exec($sql, $params);
}

我的问题是什么?我找不到解决方案。

非常感谢您的帮助。

谢谢

最佳答案

基本语法 sql 查询 'INSERT' 是

INSERT [INTO] tbl_name [(col_name,...)]
VALUES (expression,...),(...)

如果你使用一些参数,你需要加上括号:

$sql = "INSERT INTO " . $this->_table;
$sql .= "(education, avatar) VALUES (?, ?)";
$params = array(
urlencode($patient->getEducation()),
urlencode($patient->getAvatar()),
);
return $this->exec($sql, $params);
}

然后在 $this->exec 中写什么?

关于php - 将数据从php插入数据库mysql表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33292109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com