这个问题非常适合我的需求,因此我找不到最好的方法。
我想做的是从表中获取name
并合并到一个数组中,最终得到这样的结果:surname
people
"Bob Jones","Tony Wright",
.. ETC。
我为此使用 PDO。这是我所拥有的:
$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);
}
我已经尝试了一些事情,但我只是被这段代码困住了。非常感谢任何帮助或建议。