我正在尝试选择带花括号的列,但该列有前缀,例如:
//sql to run
$sql = "SELECT * FROM trades
WHERE trade_market = ?
AND trade_buysell = ?
" . $order . "";
//run the sql
$tickersHigh = $database->prepare($sql);
$tickersHigh->execute(array(strtolower($market), $buysell));
//fetch the results
$tickerHigh = $tickersHigh->fetch();
//return the results
return $tickerHigh->trade_{$type};
由于我已将trade_添加到我的列名称,因此它不再起作用,它曾经如此工作:
return $tickerHigh->{$type};
但是我最近在我的列中添加了前缀trade_
,如下所示:
return $tickerHigh->trade_{$type};
我收到错误:
找不到列:1054未知栏'价格'在'订单条款'
应该选择trade_price
而不仅仅是price
那么如何才能使用我的前缀呢?
我的表:
CREATE TABLE `trades` (
`trade_id` int(11) NOT NULL,
`trade_amount` text NOT NULL,
`trade_market` varchar(25) NOT NULL,
`trade_cost` varchar(25) NOT NULL,
`trade_fee` varchar(25) NOT NULL,
`trade_time` time NOT NULL,
`trade_user` varchar(25) NOT NULL,
`trade_ip` varchar(25) NOT NULL,
`trade_price` text NOT NULL,
`trade_buysell` text NOT NULL,
`trade_date` datetime NOT NULL,
`trade_maincoin` text NOT NULL,
`trade_charttime` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
答案 0 :(得分:1)
尝试
return $tickerHigh->{"trade_$type"};