gpt4 book ai didi

php - 从表中选择一个值并将其传递给变量 - php mysql

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

我想创建名为 $start 的变量。作为一个值,我想从名为 table_ex 的表的最后一行名为 timestamp 的列中选择一个值。到目前为止我有这个:

class Main {
//some other code

function dataBaseConnect(){
//well working part
}

function getTimeValue(){
$sql = "SELECT `timestamp` FROM `table_ex` WHERE id=(SELECT MAX(id) FROM `table_ex`)";
$this->start = $this->handler->query($sql, PDO::FETCH_COLUMN, 0);
}

function printVal(){
$this->dataBaseConnect();
$this->getTimeValue();
$this->messOuput = "Sth text " .$this->start;
}
}

问题是变量没有得到我想要的值。谁能告诉我问题出在哪里?

最佳答案

也许这对你有用:

function getTimeValue()
{
// note the table name is now used in the inner query
$sql = "SELECT `timestamp` FROM `table_ex` WHERE id=(SELECT MAX(id) FROM `table_ex`)";
$this-start = $this->handler->query($sql, PDO::FETCH_COLUMN, 0);
}

关于php - 从表中选择一个值并将其传递给变量 - php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38997489/

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