Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
$pre ->bindColumn('name',$name); // 把读取出来的数据放到变量中
while($pre->fetch(PDO::FETCH_ASSOC)){
echo '姓名:'.$name; // 输出 姓名:欧阳克
}
例1
header('content-type:text/html;charsetutf-8');
例2
try {
$pdo = new PDO('mysql:host=127.0.0.1;dbname=php', 'root', 'root');
} catch (PDOException $e) {
echo '数据库连接失败' . $e->getMessage();
}
$pdo->query('SET NAME utf8');
$pdo = null; // 数据为空
unset($pdo); // 删除数据库
SELECT count(*) FROM `user` // 查询表单里面有多少条数据
SELECT `accoun` as a FROM `user`
创建类的时候,是 class 类名 + {} class 是关键词
new一个对象时并非一定是new 类名 + (), 其中()有时候能够省略的,主要看你的构造器是否加入参数,
例
class Shop
{
public $name;
public $number;
public function __construct($n, $b)
{
$this->name = $n;
$this->number = $b;
$this->gw();
}
public function gw()
{
return '今天我在商场购物:';
}
public function shopping()
{
return '购买文具';
}
public function __destruct()
{
echo ',买好了';
}
}
$xiaoming = new Shop('语文书', '26');
echo $xiaoming->name . ':';
echo $xiaoming->number . '本';
echo $xiaoming->shopping;
echo '<hr>';
$xiaohua = new Shop('数学书', '23');
echo $xiaohua->name . ':';
echo $xiaohua->number . '本';
echo $xiaohua->shopping;
echo '<hr>';