Blogger Information
Blog 10
fans 1
comment 0
visits 6552
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
2月22日作业_PDO_day1
红色熊猫的博客
Original
593 people have browsed it

<?php


// 1. PDO连接数据库的过程与参数设置


$pdo=new PDO("mysql:host=127.0.0.1;dbname=test",'root','root');


// 2. 如何创建PDO预处理对象: prepare()方法


$sql="SELECT id name age FROM test where name=:name and age>:age";

$stmt=$pdo->prepare($sql);

$name='富贵';

$age='20';

$stmt->bindParam('name',$name);

$stmt->bindParam('age',$age,PDO::PARAM_INT);

$res=$stmt->execute();

var_dump($res);


// 3. bindParam()与bindValue()

bindParam()  只能绑定变量,不能是常量

bindValue()   可以绑定变量  也可以绑定常量



//  4. execute()直接传参

$res=$stmt->execute(array('name'=>$name,'age'=>$age));


// 5. fetch() 和 fetchAll()的区别与联系

fetch()   获取查询条件中满足条件的第一条数据

fetchAll()  获取查询条件中所有满足条件的数据



// 6. bindColumn()的功能 

将列绑定到PHP变量


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post