Skip to main content
added 6 characters in body
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

I have written this function. It that surprisingly works. (I didn´tdidn't really know what iI was doing,doing; just a little experiment.) It is supposed to count rows selected by a PDO query. 

Is it well written? It works, but iI am just asking, as it is my first more complex-complex function.

function countRows($sql, $parameters){
            require("include/db.php");

            $result = $db->prepare($sql); 
            foreach ($parameters as $key => $parameter) {
                    $result->bindParam($key, $parameter);
            }

            $result->execute(); 
            $number_of_rows = $result->fetchColumn();

            return $number_of_rows;

            }

I have written this function. It surprisingly works. (I didn´t really know what i was doing, just a little experiment.) It is supposed to count rows selected by PDO query. Is it well written? It works, but i am just asking, as it is my first more complex function.

function countRows($sql, $parameters){
            require("include/db.php");

            $result = $db->prepare($sql); 
            foreach ($parameters as $key => $parameter) {
                    $result->bindParam($key, $parameter);
            }

            $result->execute(); 
            $number_of_rows = $result->fetchColumn();

            return $number_of_rows;

            }

I have written this function that surprisingly works. (I didn't really know what I was doing; just a little experiment.) It is supposed to count rows selected by a PDO query. 

Is it well written? It works, but I am just asking, as it is my first more-complex function.

function countRows($sql, $parameters){
            require("include/db.php");

            $result = $db->prepare($sql); 
            foreach ($parameters as $key => $parameter) {
                    $result->bindParam($key, $parameter);
            }

            $result->execute(); 
            $number_of_rows = $result->fetchColumn();

            return $number_of_rows;

            }
edited title
Link
200_success
  • 145.6k
  • 22
  • 191
  • 481

Is this function good? Function to count rows in a database query result

Source Link
Marinaro
  • 51
  • 1
  • 6

Is this function good?

I have written this function. It surprisingly works. (I didn´t really know what i was doing, just a little experiment.) It is supposed to count rows selected by PDO query. Is it well written? It works, but i am just asking, as it is my first more complex function.

function countRows($sql, $parameters){
            require("include/db.php");

            $result = $db->prepare($sql); 
            foreach ($parameters as $key => $parameter) {
                    $result->bindParam($key, $parameter);
            }

            $result->execute(); 
            $number_of_rows = $result->fetchColumn();

            return $number_of_rows;

            }