At first, it was written.
$pdo =new PDO ("Mysql:host=localhost;dbname=t1", "Root", "");
$sth = $pdo->query (' select * from blog ');
$result = $sth->fetchall (PDO::FETCH_ASSOC);
foreach ($result as $v) {
print_r($v);
}
?>
Later they told me to write like this, but it's the same as the original, how should I change it?
$pdo =new PDO ("Mysql:host=localhost;dbname=mysql", "Root", "");
$sth = $pdo->query (' select * from user ');
$result = $sth->fetchall (PDO::FETCH_ASSOC);
$tmp _ary=array ();
foreach ($result as $v) {
$tmp_ary[]=array_values($v);
}
Echo '
';
Print_r ($tmp _ary);
Echo '
';
Reply content:
At first, it was written.
$pdo =new PDO ("Mysql:host=localhost;dbname=t1", "Root", "");
$sth = $pdo->query (' select * from blog ');
$result = $sth->fetchall (PDO::FETCH_ASSOC);
foreach ($result as $v) {
print_r($v);
}
?>
Later they told me to write like this, but it's the same as the original, how should I change it?
$pdo =new PDO ("Mysql:host=localhost;dbname=mysql", "Root", "");
$sth = $pdo->query (' select * from user ');
$result = $sth->fetchall (PDO::FETCH_ASSOC);
$tmp _ary=array ();
foreach ($result as $v) {
$tmp_ary[]=array_values($v);
}
Echo '
';
Print_r ($tmp _ary);
Echo '
';
array_values
Learn about the PHP removal key function.
"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 takes out the data, it seems that PDO has the information of the field.