Mysqli查询无法使用临时表

时间:2015-03-19 17:30:26

标签: php mysql mysqli

有人可以解释为什么这个在mysql上运行的查询不能在mysqli上运行吗?

$queryCreateTemp = "CREATE TEMPORARY TABLE IF NOT EXISTS receita_anual_temp AS (SELECT servmensal_empresa_id AS receita_anual_temp_empresa_id, SUM(servmensal_receita) AS receita_anual_temp_receita_anual FROM servmensal GROUP BY servmensal_empresa_id)";

$mysqli->query($queryCreateTemp);

提前致谢!

错误是:

Access denied for user 'user'@'%' to database 'database'

感谢Ar7proface。

1 个答案:

答案 0 :(得分:0)

<?php
$ql="CREATE TEMPORARY TABLE IF NOT EXISTS receita_anual_temp AS (SELECT servmensal_empresa_id AS receita_anual_temp_empresa_id, SUM(servmensal_receita) AS receita_anual_temp_receita_anual FROM servmensal GROUP BY servmensal_empresa_id)";
if ($mysqli->query($ql) === TRUE) {
    printf("right <br>");
}else{
    printf("fail <br>");
} 
?>
result=right;

记住它是一个临时表 - 在查询结束时删除表。