我想创建名为$start
的变量。作为一个值,我想从名为timestamp
的表的最后一行中选择一个名为table_ex
的列中的值。到目前为止,我有这个:
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;
}
}
问题是变量没有得到我想要的那个值。谁能解释一下我的问题在哪里?
答案 0 :(得分:1)
也许这对你有用:
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);
}