Tell me the best way to find out the number of records in the MySQL database table using OOP ( PHP ).

Closed due to the fact that the issue is too general for participants Dmitriy Simushev , VenZell , VAndrJ , Grundy , zRrr 12 May '16 at 18:15 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • ten
    Doesn't it seem to you that the number of records in MySQL has nothing to do with the style of writing code in PHP, even if it has at least functional code, the method will be the same. - Vladimir Klykov
  • 7
    Tell me the best way to find out the temperature of the air with a screwdriver (with a black pen). - Vladimir Gordeev
  • 2
    Calibrate screwdriver is what? if there is a calibration tool, I think we can solve your puzzle :) - Vladimir Klykov
  • one
    > Tell me the best way to find out> air temperature with the help of> screwdriver (with black handle). By analogy with the calculation of height using a barometer: unscrew the thermometer from a neighbor, sell a screwdriver and buy a thermometer :) - zenith
  • one
    but in my opinion, the guy simply brought up some kind of college problem as a question. At least, the question wording style looks exactly like this - DreamChild

2 answers 2

OOP say) PDO to help you!

  • Oh, right, docks rulez! - VladD

You can do the following:

<?php try { $pdo = new PDO( 'mysql:host=localhost;dbname=test', 'root', '', [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]); $query = "SELECT COUNT(*) AS total FROM tbl"; $cnt = $pdo->query($query); echo $cnt->fetch()['total']; } catch (PDOException $e) { echo "Ошибка выполнения запроса: " . $e->getMessage(); }