This question is quite specific for my needs, hence I can't find the best way to do this.
What I would like to do is fetch name
and surname
from the table people
and combine both into an array to end up with such results:
"Bob Jones","Tony Wright",
.. etc.
I'm using PDO for this. Here is what I have:
$attrs = array(PDO::ATTR_PERSISTENT => true);
// connect to PDO
$pdo = new PDO("mysql:host=localhost;dbname=new", "root", "root", $attrs);
// the following tells PDO we want it to throw Exceptions for every error.
// this is far more useful than the default mode of throwing php errors
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn = $pdo->prepare("SELECT name, surname FROM people");
$conn->execute();
$results = $conn->fetchAll();
foreach($results as $row){
$fullName = $row['name'] . "," . $row['surname'];
print_r($fullName);
}
I have tried a few things, I'm just stuck with this code at minute. Any help, or suggestions is much appreciated.