这是我从表格comment
获取字段kh_comments
的方式。
public function get_the_comment($internal_page_id) {
$conn = new mysqli($this->servername, $this->username, $this->password, $this->db_name);
if (!empty($internal_page_id)) {
$stmt = $conn->prepare("SELECT comment FROM kh_comments WHERE page_id = ?");
$stmt->bind_param('s', $internal_page_id);
}
$stmt->execute();
$stmt->bind_result($comment);
while ($stmt->fetch()) {
return $comment;
}
$stmt->close();
$conn->close();
}
现在让我们说我们在第二个参数上有一个像这样的数组
public function get_the_comment($internal_page_id, $array) {
和$array
看起来像这样:
array(3) {
[0]=>
string(4) "name"
[1]=>
string(3) "age"
[2]=>
string(8) "location"
}
如何使用数组的值从MySQL表中获取具有相同列名的值?
结果将是这样的:
$stmt = $conn->prepare("SELECT comment FROM name, age, location WHERE page_id = ?");
...