猿问

如果我想把mysql返回的结果集放进php的数组中?该怎么做?

<?php
$dsn = "mysql:host=localhost;dbname=palace_banquet";
$user = "root";
$password = "";
$dbh = new PDO($dsn, $user, $password);
$pdo = new PDO("mysql:host=localhost;dbname=palace_banquet","root","");
$pdo->query("SET NAMES utf8");
$ysql="select n_account from noodles_member where n_username='{$uid}'";
$yarr=$pdo->Query($ysql);
$yarr[0][1];//总额
这里$yarr[0][1]报错
我用pdo链接数据库的

holdtom
浏览 127回答 2
2回答

慕斯王

$pdo = new PDO('mysql:host=localhost;dbname=','root','');$data = $pdo->query('SELECT * FROM `user`');foreach($data as $v){echo $v['id'];}正常情况下你还应该处理异常try{$pdo = new PDO('mysql:host=localhost;dbname=','root','');$data = $pdo->query('SELECT * FROM `user`');foreach($data as $v){print_r($v);}}catch(PDOException $e){}

HUX布斯

直接print_r($yarr);看看是什么结果
随时随地看视频慕课网APP
我要回答