ArnisR Posted June 28, 2012 Report Share Posted June 28, 2012 (edited) Izmantojot PHP MySQL funkcijas, tiek veikts vaicājums šādā formā: $result = mysql_query("SELECT * FROM `users` WHERE id = 1"); if($result){ if(mysql_num_rows($result) != 0){ echo "Datubāzē ir tāds ieraksts!"; } else { echo "Datubāzē nav neviena ieraksta!"; } } else { echo "Kaut kas nav kārtībā ar vaicājumu!"; } Svarīgi ir fiksēt šos trīs vaicājuma rezultātus: - kad vaicājums ir kļūdains, - kad netika atrasti ieraksti - un kad ieraksti tika atrasti. Bet kā šo sistēmu vislabāk organizēt, izmantojot PDO objektu? Vai vienmēr jālieto try/catch, vai arī ir kāda cita metode?! Šādi tiek viekts PDO vaicājums: $stmt = $dataBase->prepare("SELECT * FROM `users` WHERE id = :id"); $stmt->execute(array(":id" => 1)); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); Edited June 28, 2012 by ArnisR Quote Link to comment Share on other sites More sharing options...
y2ok Posted June 28, 2012 Report Share Posted June 28, 2012 (edited) Netesteju, bet vajadzetu stradat - $query = $stmt->execute(...); if($query) { if($query->rowCount()) { echo 'tika atrasti ieraksti'; } else { echo ' netika atrasti ieraksti'; } } else { echo ' kluda querija'; } P.S. - http://www.php.net/m...dostatement.php EDIT: Labots pec Kavacky labojuma. Edited June 28, 2012 by y2ok Quote Link to comment Share on other sites More sharing options...
Kavacky Posted June 28, 2012 Report Share Posted June 28, 2012 if ($query->rowCount()) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.