全局临时表创建失败

时间:2012-01-27 03:50:15

标签: php mysql

我有一些链接,可以借助数据库中的临时数据显示iframe上的数据 我在查询字符串

的帮助下获取此数据

带有链接的页面是

    <style type="text/css">
a
{
    text-decoration:none;
}
.Menu
{
    width:150px;
    float:left;
}
.fr
{
    width:800px;
    height:800px;
    float:right
}

</style>
<div class="Menu">
<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
$sql="select * from NSEIndices_latest";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$tpnt=$row['TickerPlantCode'];  //nse indice code
$indexname=$row['IndexName']; //nse indice index name
?>
  <tr>
    <td><a href="http://mastertrade.in/master/wpfiles/gtnsegainers.php?tpnt=<?php echo $tpnt;?>&indexname=<?php echo $indexname;?>" target="fr"><?php echo $indexname;?></a><br></td>
  </tr>
    <?php }?>
    </div>
    <div class="fr">
    <iframe height="780" width="780" scrolling="no" name="fr"></iframe>
    </div>

现在来自上一页的链接在此页面的查询字符串的帮助下获取数据,临时表由各种表中的collectiong数据创建 但是从该临时表中检索数据时出现错误

临时表的页面是

    <table class="table" cellspacing="0" width="100%">
  <tr>
    <td align="left" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9;">Company Name
      </th>
    <td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">High
      </th>
    <td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Low
      </th>
    <td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Last Price
      </th>
    <td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Prv Close
      </th>
    <td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">Change
      </th>
    <td align="center" valign="middle" style="border:#e7e7e7 1px solid; background-color:#f9f9f9; background-color:#f9f9f9;">%Gain
      </th>
  </tr>
<?php
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
$tpnt=$_GET['tpnt'];
$indexname=$_GET['indexname'];
echo "1".$indexname. "<br>";
$query="SELECT nsepricequotes_latest.Symbol, nsepricequotes_latest.CompanyName, nsepricequotes_latest.HighPrice, nsepricequotes_latest.LowPrice, nsepricequotes_latest.LastTradedPrice, nsepricequotes_latest.ClosePrice, nsepricequotes_latest.NetChange, nsepricequotes_latest.PercentChange, nse_index_constituents.Tickerplant_index_code,nse_index_constituents.NSE_Index_Name
FROM nsepricequotes_latest, nse_index_constituents
WHERE nsepricequotes_latest.TickerPlantCode = nse_index_constituents.TickerPlant_scrip
AND PercentChange >0
ORDER BY PercentChange DESC ";
$result=mysql_query($query);
echo "2".$indexname. "<br>";
while($row1=mysql_fetch_array($result))
{
$Symbol1=$row1['Symbol'];
$CompanyName1=$row1['CompanyName'];
$HighPrice1=$row1['HighPrice'];
$LowPrice1=$row1['LowPrice'];
$LastTradedPrice1=$row1['LastTradedPrice'];
$ClosePrice1=$row1['ClosePrice'];
$NetChange1=$row1['NetChange'];
$PercentChange1=$row1['PercentChange'];
$Tickerplant_index_code1=$row1['Tockerplant_index_code1'];
$NSE_Index_Name1=$row1['NSE_Index_Name'];
}
echo "3".$indexname. "<br>";
$tbl="create GLOBAL TEMPORARY TABLE temppice(Symbol varchar(100),CompanyName varchar(200),HighPrice float(50),LowPrice float(50),LastTradedPrice float(50),ClosePrice float(50),NetChange float(50),PercentChange float(50),Tickerplant_index_code varchar(100),NSe_Index_Name varchar(100)) ON COMMIT DELETE ROWS;";
$res=mysql_query($tbl);
if (!$res) { die('Temporary table creation failed: ' . mysql_error()); }
if(mysql_error())die(mysql_error());
$intbl="Insert into temppice values('$Symbol1','$CompanyName1','$HighPrice1','$LowPrice1','$LastTradedPrice','$ClosePrice1','$NetChange1','$PercentChange1','$Tockerplant_index_code1','$NSE_Index_Name1')";
mysql_query($intbl);
if(mysql_error())die(mysql_error());
echo "4".$indexname. "<br>";
$query1="Select * from temppice where NSE_Index_Name=$indexname";
$result1=mysql_query($query1);
//if(mysql_error())die(mysql_error());
mysql_connect("localhost","dbname","password");
mysql_select_db("dbname");
while($row=mysql_fetch_array($result1, MYSQL_BOTH))
{
$symbol=$row['Symbol'];  
$CompanyName=$row['CompanyName'];
$HighPrice=$row['HighPrice'];
$LowPrice=$row['LowPrice'];
$previousclose=$row['LastTradedPrice'];
$ClosePrice=$row['ClosePrice'];
$netChange=$row['NetChange'];
$percentagechange=$row['PercentChange'];
?>

  <tr>
    <td align="left" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $CompanyName;?></td>
    <td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $HighPrice;?></td>
    <td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $LowPrice;?></td>
    <td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $previousclose; ?></td>
   <td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $ClosePrice;?></td>
    <td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $netChange;?></td>
    <td align="center" valign="middle" style="border-right:#e7e7e7 1px solid; border-left:#e7e7e7 1px solid ;border-bottom:#e7e7e7 1px solid;"><?php echo $percentagechange;?></td>
  </tr>
  <?php } ?>
</table>

我得到的错误是

  

临时表创建失败:您的SQL中有错误   句法;查看与MySQL服务器版本对应的手册   在'GLOBAL TEMPORARY TABLE附近使用正确的语法   temppice(符号varchar(100),CompanyName varchar(200),Hig'在第1行

1 个答案:

答案 0 :(得分:0)

According to the manual MySQL CREATE TABLE语法不支持global关键字。那appears to be an Oracle thing。同样地,我认为ON COMMIT DELETE ROWS子句是Oracle语法的一部分,它在MySQL中也不起作用。

如果删除这两部分,它可能会起作用:

 $tbl=<<<SQL
create TEMPORARY TABLE temppice (
    Symbol                 varchar(100),
    CompanyName            varchar(200),
    HighPrice              float(50),
    LowPrice               float(50),
    LastTradedPrice        float(50),
    ClosePrice             float(50),
    NetChange              float(50),
    PercentChange          float(50),
    Tickerplant_index_code varchar(100),
    NSe_Index_Name         varchar(100)
);
SQL;