MySQL dotaz, nette vráti NULL
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- Andurit
- Člen | 131
Ahojte,
snažím sa napísať jednoduchý SQL dotaz aby mi vypísal počet riadkov
v tabulke serach_log, kde column successful nie je NULL a user je napr
„FERO“
Command som si napísal a spustil v PHP MY ADMINE a vypísal mi krásne
výsledok
SELECT COUNT(id) FROM `search_log` WHERE successful IS NOT NULL AND user = "Fero"
V mojej funkcii mi ale dump vracia NULL, môže mi poradiť niekto čo robim nesprávne? Kľudne ma poučiť ako na to?
Model:
function getUserSuccessSearch($username)
{
return $this->db->query('SELECT COUNT(id) FROM `search_log` WHERE successful IS NOT NULL AND user = "'.$username.'"'); //vykona sa len ak ho zacneme potrebovať
}
Presenter:
function renderDetail($id, $username)
{
if (!$id) {
$this->error();
}
$this->template->userInfo = $this->facade->detailbyId($id);
$this->template->userlogs = $this->facade->getUserLog($username);
$this->template->userSuccessful = $this->facade->getUserSuccessSearch($username);
}
dump:
array (1)
"$userSuccessful" => Nette\Database\ResultSet #64e9
connection private => Nette\Database\Connection #81c8
supplementalDriver private => Nette\Database\Drivers\MySqlDriver #67f2
connection private => Nette\Database\Connection #81c8 { ... }
pdoStatement private => PDOStatement #1a97
queryString => "SELECT COUNT(id) FROM `search_log` WHERE successful IS NOT NULL AND user = "michal"" (83)
result private => NULL
resultKey private => -1
results private => NULL
time private => 0.00049996376037598
queryString private => "SELECT COUNT(id) FROM `search_log` WHERE successful IS NOT NULL AND user = "michal"" (83)
params private => array ()
types private => NULL
Editoval Andurit (29. 5. 2015 15:41)
- David Matějka
- Moderator | 6445
musis na tom vysledku zavolat nekterou z fetch*
metod, treba
primo fetch
- David Matějka
- Moderator | 6445
ResultSet ten PDOStatement prochazi lazy – tedy az kdyz nad tim zacnes iterovat nebo zavolas nejakou fetch metodu