Hello, I'm having trouble with a script timing out. Not sure what's happening because the line that gives the error is just a PDO object instantiation. Would love some help. If there doesn't seem to be anything wrong there I'm not sure what's going on. There is a bit of other code called from custom objects, but I don't think anything too heavy, just some sql calls. The function is below. $friendHandler->get_friends($user->return_username(), $letter); The script calling the function. // Set starting letter and page $letter = 'a'; $page = 1; if(isset($_GET['letter'])) { $letter = base64_decode($_GET['letter']); } $friendHandler = new cfriendhandler; $friendHandler->set_letters($user->return_username()); $letterString = $friendHandler->return_letterstring(); echo $letterString; // get and return friends $friendHandler->get_friends($user->return_username(), $letter); $friends = $friendHandler->return_friends(); var_dump($friends); PHP: The function. function get_friends($userNameSet, $letterSet) { global $dsn, $dbUserName, $dbPassword; $dbConnect = new PDO($dsn, $dbUserName, $dbPassword, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); $sql = $dbConnect->prepare("SELECT `friend` FROM `friends` WHERE `userName` = ? AND `friend` LIKE = ? AND `status` = ?"); try{ $sql->execute($userNameSet, ''.$letterSet.'%', 'friend'); $this->friends = $sql->fetchAll(); }catch(\PDOException $e){ } } Code (markup):
If I don't remember completely wrong, you need to add the '%' to the variable before you put it in the array - hence it should be something like this: $letterset = '%'.$letterset.'%'; $sql->execute($userNameSet, $letterset, 'friend') // although that last one could just as well just be put in the query itself Code (markup):
That is also correct, of course - you'd need to change the argument to: $sql->execute(array($userNameSet, $letterset, 'friend')); PHP: or, if you're using a newer version of PHP, I think this'll work just fine: $sql->execute([$userNameSet, $letterset, 'friend']); PHP: