标签:echo root mysq from sage prepare order attribute mysql
<?php
$dsn = ‘mysql:host=localhost;dbname=user;charset=utf8‘;
try{
$pdo = new PDO($dsn,‘root‘,‘123456‘);
$pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);
}catch(PDOException $e)
{
die(‘数据库连接失败‘.$e->getMessage());
}
try{
$stmt = $pdo->prepare(‘select `name`, `password`, `money` from user‘);
$stmt->execute();
$stmt->bindColumn(‘name‘,$name);
$stmt->bindColumn(‘password‘,$pwd);
$stmt->bindColumn(‘money‘,$money);
echo "<table border=‘1‘ width=‘800‘ align=‘center‘>";
while($stmt->fetch()){
echo ‘<tr>‘;
echo ‘<td>‘.$name.‘</td>‘;
echo ‘<td>‘.$pwd.‘</td>‘;
echo ‘<td>‘.$money.‘</td>‘;
echo ‘</tr>‘;
}
echo "</table>";
//$result = $stmt->fetch(PDO::FETCH_ASSOC);
//$result = $stmt->fetch(PDO::FETCH_NUM);
//$result = $stmt->fetch();
//$result = $stmt->fetchAll();
//print_r($result);
}catch(PDOException $e){
echo $e->getMessage();
}
标签:echo root mysq from sage prepare order attribute mysql
原文地址:https://www.cnblogs.com/rjbc/p/11361209.html