-5

php PDOを使用してmysqlデータベースからデータを取得して表示するにはどうすればよいですか?これが私のコードです。私はmysql_functionを使用してそれを行う方法を知っています。これは私が試したものですが、これまでのところ何も表示されません。

 #query to display the users 
$select_all=("select * from tish_user
inner join tish_clientinfor on  tish_user.user_id = tish_clientinfor.user_id
inner join tish_images on  tish_user.user_id = tish_images.user_id
inner join tish_security on  tish_user.user_id = tish_security.user_id");
$result = $con->query($select_all);
#if the statement is success full
if($result !== false ){
$cols = $result->columnCount();
#echo number of rows 
echo 'num rows'.$cols.'</br>';
#pass the result set 
foreach($result as $row){
echo  $row['username'].'</br>';
}
}
?>
4

2 に答える 2

2

準備後、実行する必要があります。

このような:

$all->execute();

その後、結果をループします。

while( $row = $all->fetch() )
    print_r( $row );

PDO::FETCH_ASSOCさらに、連想結果のフェッチステートメントを指定できます。

while( $row = $all->fetch(PDO::FETCH_ASSOC) )
    print_r( $row );
于 2013-02-13T09:28:19.770 に答える
2

この答えを試してください

$sql = ("select * from user");
$result = $con->$query($sql);
#if the statement is success full
if ($result) !== false ){
$cols = $result->columnCount();
#echo number of rows 
echo 'num rows'.$cols.'</br>';
#pass the result set 
foreach($result as $row){
echo     $row['username'].'</br>';
}
于 2013-02-13T10:01:11.393 に答える