gpt4 book ai didi

PHP 与 Phpmyadmin

转载 作者:可可西里 更新时间:2023-11-01 08:01:13 24 4
gpt4 key购买 nike

我得到了我在 phpmyadmin 上执行的代码,它 100% 有效

Create Temporary Table Searches  ( id int, dt datetime);
Create Temporary Table Searches1 ( id int, dt datetime, count int);

insert into Searches(id, dt) select a.id, now() from tblSavedSearches a;

insert into Searches1(id, dt, count)
select
b.savedSearchesId,
(select c.dt from tblSavedSearchesDetails c where b.savedSearchesId = c.savedSearchesId order by c.dt desc limit 1) as 'dt',
count(b.savedSearchesId) as 'cnt'
from tblSavedSearchesDetails b
group by b.savedSearchesId;

insert into tblSavedSearchResults(savedSearchId,DtSearched,isEnabled)
select id,now(),0 from Searches where not id in (select savedSearchId from tblSavedSearchResults);

update tblSavedSearchResults
inner join Searches1 on tblSavedSearchResults.savedSearchId = Searches1.id
Set tblSavedSearchResults.DtSearched = Searches1.dt, tblSavedSearchResults.isEnabled = 1;

然而,当我在 php 中放入与下面相同的代码时,它会生成一个错误

$dba = DbConnect::CreateDbaInstance(); 
$query = "";

$query.="Create Temporary Table Searches ( id int, dt datetime); ";
$query.="Create Temporary Table Searches1 ( id int, dt datetime, count int); ";

$query.="insert into Searches(id, dt) select a.id, now() from tblSavedSearches a; ";

$query.="insert into Searches1(id, dt, count) ";
$query.="select ";
$query.=" b.savedSearchesId, ";
$query.=" (select c.dt from tblSavedSearchesDetails c where b.savedSearchesId = c.savedSearchesId order by c.dt desc limit 1) as 'dt', ";
$query.=" count(b.savedSearchesId) as 'cnt' ";
$query.="from tblSavedSearchesDetails b ";
$query.="group by b.savedSearchesId; ";

$query.="insert into tblSavedSearchResults(savedSearchId,DtSearched,isEnabled) ";
$query.="select id,now(),0 from Searches where not id in (select savedSearchId from tblSavedSearchResults); ";

$query.="update tblSavedSearchResults ";
$query.="inner join Searches1 on tblSavedSearchResults.savedSearchId = Searches1.id ";
$query.="Set tblSavedSearchResults.DtSearched = Searches1.dt, tblSavedSearchResults.isEnabled = 1; ";

$dba->DbQuery($query) or die(mysql_error());

出现以下错误

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Create Temporary Table Searches1 ( id int, dt datetime, count int) insert into S' at line 1

如果有人可以帮助我...

谢谢

最佳答案

如果您的 $dba->DbQuery($query) 方法实际上使用了 mysql_query (我想它确实如此,因为您正在使用 mysql_error),那么,您不能在每次调用时执行多个查询 (引用) :

mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.


您必须:

  • 分离您的查询,并为每个查询调用一次 mysql_query
    • 应该很简单,在这里:不要将所有查询连接到 $query 中,只需一个接一个地执行它们。
  • 或者停止使用mysql_*,开始使用MySQLi ,它提供了一个 mysqli_multi_query功能

关于PHP 与 Phpmyadmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2749616/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com