我終於在這裏創建了我的帳戶。你已經幫了我很長時間了,但是這次我在這裏找不到答案。Mysqli使用mysql變量錯誤
我是MySqli中的新成員,我試圖運行一個在phpMyAdmin中工作的腳本。
當我嘗試使用'mysql變量'時會出現問題。代碼和錯誤如下。
$consulta = "SET @var= (SELECT ticket_id FROM ost_ticket WHERE number = 410037);
SELECT DISTINCT a.number, a.created, b.address,
SELECT DISTINCT title FROM ost_ticket_thread a WHERE a.ticket_id = @var AND a.source LIKE 'API')title,
SELECT DISTINCT body FROM ost_ticket_thread a WHERE a.ticket_id = @var AND a.source LIKE 'API')body,
d.state,
c.body resposta
FROM ost_ticket a
LEFT JOIN ost_user_email b ON b.user_id = a.user_id
LEFT JOIN ost_ticket_thread c ON c.ticket_id = a.ticket_id
LEFT JOIN ost_ticket_status d ON d.id = a.status_id
WHERE a.ticket_id = @var AND c.id = (SELECT MAX(a.id) FROM ost_ticket_thread a WHERE a.ticket_id = @var) ";
$resultado = $MySQLi->query($consulta) OR trigger_error($MySQLi->error, E_USER_ERROR);
$cont = 0;
while ($informacao = $resultado->fetch_object()) {
$data[$cont] = array(
'numprot' => $informacao->number,
'email' => $informacao->address,
'assunto' => $informacao->title,
'status' => $informacao->state,
'body' => $informacao->body,
'resposta' => $informacao->resposta,
'dtcriacao' => $informacao->created,
);
$cont++;
}
echo "{'lista':".json_encode($data)."}";
正如我所說,它在phpMyAdmin中工作正常,但我得到了mysqli查詢函數中的後續錯誤。
Fatal error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT distinct a.number,a.created,b.address, (select distinct title from ost_t' at line 3 in /home/u605553750/public_html/JSONResposta.php on line 22
在
$resultado = $MySQLi->query($consulta) OR trigger_error($MySQLi->error, E_USER_ERROR);
What's對mysqli的運行它以正確的方式行22場比賽?
感謝 布魯諾
當您複製並粘貼在你的PHP管理這個SQL查詢它執行?看起來你有拼寫錯誤,但我不知道'MariaDB'是否允許:'b.address,(另一個選擇)x' ...另外,將SQL命令保持爲大寫字母,使維護更容易被認爲是好的做法 – Bonatti
It確實有效。我把它編碼在phpMyAdmin上。 –
我認爲問題在於使用「SET @var = ...」和「;」到底。 –