0

How can I get the number of records in mySQL DB via PDO?.

My codes: (But something is wrong.It is not working.)

    function AlandakiDegerlerToplami ($tablo,$alan) 

 {  

     $dsn = 'mysql:host='.$host.';dbname='.$veritabaniadi;

    try {
        $this->conn = new PDO($dsn, $kullaniciadi, $sifre);
    } catch (PDOException $e) {
        echo vthatasi .':'. $e->getMessage();
    }

    $veriler = $this->conn->prepare('SELECT sum('.$alan.') as adet from '.$tablo);
    $toplam=$veriler->execute();

    return $toplam['adet'];
 }


      function TablodakiKayitSayisi ($tablo) 

 {  

     $dsn = 'mysql:host='.$host.';dbname='.$veritabaniadi;

    try {
        $this->conn = new PDO($dsn, $kullaniciadi, $sifre);
    } catch (PDOException $e) {
        echo vthatasi .':'. $e->getMessage();
    }

$veriler = $this->conn->prepare('SELECT count(*) as adet from '.$tablo);
        $toplam=$veriler->execute();

    return $toplam['adet'];

 }

}

Jay
  • 1,317
  • 4
  • 16
  • 40
Burhan
  • 13
  • 5

1 Answers1

0

Finally I solved my problem.

Codes:

            function AlandakiDegerlerToplamiWHERE ($tablo,$alan,$where) 

         {  

$kullaniciadi='bla';
$sifre='1234';
$veritabaniadi='deneme'; 

 $dsn = 'mysql:host='.$host.';dbname='.$veritabaniadi;

    try {
        $baglan = new PDO($dsn, $kullaniciadi, $sifre);
    } catch (PDOException $e) {
        echo vthatasi .':'. $e->getMessage();
    }
            $veriler = $baglan->query('SELECT sum('.$alan.') as adet from '.$tablo.' WHERE '.$where);

            foreach($veriler as $row) {
            return $row['adet'];      }
         }








            function TablodakiKayitSayisi ($tablo) 

         {


    $kullaniciadi='bla';
$sifre='1234';
$veritabaniadi='deneme'; 
 $dsn = 'mysql:host='.$host.';dbname='.$veritabaniadi;

    try {
        $baglan = new PDO($dsn, $kullaniciadi, $sifre);
    } catch (PDOException $e) {
        echo vthatasi .':'. $e->getMessage();
    }

              $veriler = $baglan->query('SELECT count(*) as adet from '.$tablo);
              foreach($veriler as $row) {
              return $row['adet'];      }

         }
Burhan
  • 13
  • 5