该请求适用于phpmyadmin,但不适用于我的PHP代码

时间:2013-03-13 15:16:11

标签: php sql derived-table

请允许我展示另一个例子...... 我无法在php中创建此视图(而我可以在phpmyadmin中创建)

$sql="CREATE VIEW ratings.rtgemissfitch AS
SELECT derivedtable. ISIN
FROM
(SELECT ISIN, MAX(Date_Notation_Emission) FROM ratings.ratingsemissionfitch as derivedtable GROUP BY ISIN) ";

但我可以在php中执行此操作:

$sql="CREATE VIEW ratings.rtgemissfitch AS
(SELECT ISIN, MAX(Date_Notation_Emission) FROM ratings.ratingsemissionfitch as derivedtable GROUP BY ISIN) ";

我真的不明白..首先,对不起我的英语,我是法国人.. 我真的不明白为什么运行在phpadmin上的请求在我的php代码中不起作用..probaby派生表... 所以,我希望得到最后评级惠誉: phpmyadmin中的SQL请求完美运行:

SELECT `DBFITCH`.`ISIN`, `RATING_FITCH`as FITCH_RTG
FROM
  (SELECT `ISIN`, MAX(`RATING_DATE`) as LastUpdate 
  FROM `ratings`.`ratingsemissionfitch` GROUP BY ISIN) as LAST
  INNER JOIN `ratings`.`ratingsemissionfitch` as DBFITCH
  ON
  DBFITCH.`ISIN`= LAST.`ISIN` 
  AND DBFITCH.`RATING_DATE`=LAST.LastUpdate 

在php中,以下代码无法运行:

$sql="CREATE VIEW ratings.rtgemissfitch AS 
SELECT DBFITCH.ISIN, RATING_FITCH as FITCH_RTG
FROM 
  (SELECT ISIN, MAX(RATING_DATE) as LastUpdate 
  FROM ratings.ratingsemissionfitch GROUP BY ISIN) as LAST
  INNER JOIN ratings.ratingsemissionfitch as DBFITCH
  ON
  DBFITCH.ISIN= LAST.ISIN 
  AND DBFITCH.RATING_DATE=LAST.LastUpdate"; 
  $req = $bdd->exec($sql);

请允许我展示另一个例子......

我无法在php中创建此视图(而我可以在phpmyadmin中创建)

$sql="CREATE VIEW ratings.rtgemissfitch AS
SELECT derivedtable. ISIN
FROM
(SELECT ISIN, MAX(Date_Notation_Emission) FROM ratings.ratingsemissionfitch as derivedtable GROUP BY ISIN) ";

但我可以在php中执行此操作:

$sql="CREATE VIEW ratings.rtgemissfitch AS
(SELECT ISIN, MAX(Date_Notation_Emission) FROM ratings.ratingsemissionfitch as derivedtable GROUP BY ISIN) ";

我真的不明白.. 提前谢谢,

1 个答案:

答案 0 :(得分:0)

您的数据库用户可能没有权限运行

CREATE VIEW