-1
我已經聲明瞭一個方法,它將根據表動態創建一個數據庫查詢字符串,我的代碼就像這樣。數組只能包含一個鍵值對嗎?
public function checkBeforeDelete($table = array(), $key , $value)
{
$tableCount = count($table);
$queryString = array();
for($i=0;$i<$tableCount;$i++)
{
$queryString[] = "(SELECT COUNT(*) FROM $table[$i] WHERE $key = $value)+";
}
/***********************************************************
Convert the array to a string using implode()
Remove all commas(,) using str_replace()
Remove the last character of string using substr_replace()
***********************************************************/
$queryString = substr_replace(str_replace(',','',implode(',',$queryString)),'',-2);
$queryString = 'SELECT ('. $queryString . ') AS sum';
$sth = $this->dbh->prepare($queryString);
$sth->execute();
return $sth->fetchColumn() >= 1;
}
有當$表陣列()將僅具有一個例如
$table = array('states');
單個值它仍然計數是一個數組機會。如果一個數組只包含一個鍵值對是否可以?