MySQL Returns a different number of lines on localhost vs live server for the same code


I have a simple form that needs a list of stops in the textarea and returns an id for each on the right hand side. This is my screenshot on localhost...I have the same table names, column names, number of records on both localhost and live server.

Here's the screenshot of the same page with same query on live server...

Here's the code I am using on both pages

$conn = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass);
                if(isset($_POST["busnumber"], $_POST["busroute"])){

                    $stops = explode(PHP_EOL, $_POST["busroute"]);
                    $sql = 'SELECT * FROM stops WHERE stop_name LIKE :stop';
                    $statement = $conn->prepare($sql);
                    foreach($stops as $stop){
                        $statement->bindValue(':stop', $stop);
                        $results = $statement->fetchAll();
                        foreach($results as $result){
                            echo $result['stop_id'].' '.$result['stop_name']."</br>";


As you can see, it returns the ID of the last row only on the live server. Can someone please tell me how this is possible and what I am missing?


Notice what happens when I reverse the data entered in the text area The localhost shows both the ids now

Guess what the server shows after reversing? Only the LAST ROW!

You don't need setFetchMode(). In the time I've used PDO I always had the best results with just using bindParam() and fetch() with the most default setup of PDO, which means just setting the errormode to exception and charset to utf8 like this:

        $con = new PDO("mysql:host=".$host.";dbname=".$db_name, $user, $password);
    catch(PDOException $e){
        die("ERROR ". $e->getMessage());

    $con->exec("SET NAMES utf8");

Fetching any results like this

while($r = $statement->fetch())
    echo $r['id'];

Any time when someone has used a different set up, I've noticed they've faced problems.

Try this, perhaps.