& Amp; lt ;? Php $ pdonewPDO (& quot; mysql: hostlocalhost; dbnamet1 & quot;, & quot; root & quot;, & quot;); $; gt; query (& #039; select * fromblog & #039;); $ result $ fig-& amp; gt; fetchALL (PDO: FETCH_ASSOC ); foreach ($ resultas $ v ){{... written in this way at the beginning
$ Pdo = new PDO ("mysql: host = localhost; dbname = t1", "root ","");
$…… = $ Pdo-> query ('select * from blog ');
$ Result = $ something-> fetchALL (PDO: FETCH_ASSOC );
Foreach ($ result as $ v ){
print_r($v);
}
?>
Later, I was told to write it like this, but the printed content is the same as the original one. How should I change it?
$ Pdo = new PDO ("mysql: host = localhost; dbname = mysql", "root ","");
$…… = $ Pdo-> query ('select * from user ');
$ Result = $ something-> fetchALL (PDO: FETCH_ASSOC );
$ Tmp_ary = array ();
Foreach ($ result as $ v ){
$tmp_ary[]=array_values($v);
}
Echo'
';
print_r($tmp_ary);
echo '
';
Reply content:
Written in this way at the beginning
$ Pdo = new PDO ("mysql: host = localhost; dbname = t1", "root ","");
$…… = $ Pdo-> query ('select * from blog ');
$ Result = $ something-> fetchALL (PDO: FETCH_ASSOC );
Foreach ($ result as $ v ){
print_r($v);
}
?>
Later, I was told to write it like this, but the printed content is the same as the original one. How should I change it?
$ Pdo = new PDO ("mysql: host = localhost; dbname = mysql", "root ","");
$…… = $ Pdo-> query ('select * from user ');
$ Result = $ something-> fetchALL (PDO: FETCH_ASSOC );
$ Tmp_ary = array ();
Foreach ($ result as $ v ){
$tmp_ary[]=array_values($v);
}
Echo'
';
print_r($tmp_ary);
echo '
';
array_values
Understand the function for removing keys in PHP.
"li", "sex" => 1 ), array( "user" => "er", "sex" => 2 ) ); var_dump($result); $new = array(); foreach($result as $row){ $new[] = array_values($row); } var_dump($new);
When mysql extracts data, it seems that PDO has field information.