I am using the following queries to select rows from a mysql database using PDO.
I am using this code to select multiple rows:
<?php
$contact = $pdo_conn->prepare("SELECT * from contacts WHERE company_sequence = :company_sequence AND contactstatus = :contactstatus ");
$contact->execute(array(':contactstatus' => '', ':company_sequence' => $ticket["company"]));
?>
<select name="contactsequence" id="contactsequence">
<?php foreach($contact as $contacts) {
echo '<option value="'.$contacts["sequence"].'" ';
if($ticket["contact"] == $contacts["sequence"]) {
echo 'selected="selected"';
}
echo '>'.$contacts['forename'].' '.$contacts["surname"].'</option>';
}
?>
</select>
And this for selecting a single row:
$stmt = $pdo_conn->prepare("select * from tickets where ticketnumber = :seq ");
$stmt->execute(array(':seq' => $_GET["seq"]));
$ticket = $stmt->fetch();
Is the the correct way to run PDO select queries? (Preventing sql injection etc) I have been looking online but I just wanted to double check