1

I have this method for some class

public function bindParams($query, $params, $dbh){                                      

    if (!is_array($params)){
                    die('Second Argument for "bindParams" should be arrays');
    }

                $count = 0;
                foreach($params as &$param){
                    $count++;
                    $query->bindParam($count, $param);
                }

                $query->execute();

                if (false===$query){
                    die(print_r($dbh->errorInfo()));
                }
    }

Then I cut the code of this method to a file so I can just include it from a file. Then it doesn't run, and no errors are being shown either.

public function bindParams($query, $params, $dbh){                                      

    require_once 'functions/sql/bindprams.php'; 
}

What am I missing here.

Relm
  • 7,923
  • 18
  • 66
  • 113
  • Change `require_once` to `require`, since it should run again every time method is called. – Rene Korss Oct 13 '15 at 08:02
  • @ReneKorss that helped for this function, but other functions still behave the same way even after changing to require. – Relm Oct 13 '15 at 08:17
  • when it solved this particular problem, @ReneKorss should make his comment into an answer, you should accept it, and open a new question for the other problem(s). remember that there should be only one problem (kind) per question. – hoijui Oct 13 '15 at 08:20
  • Added it as answer. Please add another question with new examples, what dosen't work and I'll take a look again. – Rene Korss Oct 13 '15 at 08:23

1 Answers1

0

As manual says

The require_once statement is identical to require except PHP will check if the file has already been included, and if so, not include (require) it again.

So it gets executed only once, but function should run it every time it's called.

Change require_once to require.

Rene Korss
  • 5,414
  • 3
  • 31
  • 38
  • The contents of this function don't work when included from another file. public function randAlpha($length){ $randstrn = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length); return $randstrn; } – Relm Oct 13 '15 at 08:48
  • Take a look at [this answer](http://stackoverflow.com/a/1314198/1960712). I think that you include it without `return`. Even your included `.php` has `return`, method also has to `return` it. – Rene Korss Oct 13 '15 at 08:54
  • @Relm Did it help you? – Rene Korss Oct 13 '15 at 14:40