我有了這個代碼,我在phpmyadmin的其中工程100%PHP VS phpMyAdmin的
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對數據庫執行操作,但功能mysql_error一個
mysqli_multi_query
()函數來獲取錯誤......所以這是最好的部分封裝。爲什麼不使用現有的訪問或抽象層,如http://docs.php.net/pdo? b)爲什麼你想一次執行多個語句(或多或少)?它不會使它們像http://en.wikipedia.org/wiki/ACID中的原子一樣... – VolkerK 2010-05-01 10:52:44