-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcPDO.php
55 lines (54 loc) · 1.67 KB
/
fcPDO.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
function getCategory(){
try {
$dsn="mysql:host=localhost;dbname=web;charset=utf8";
$sql="select * from itcast_category";
$pdo=new PDO($dsn,"root",'');
$result=$pdo->query($sql);
if($result){
while($row=$result->fetch(PDO::FETCH_ASSOC)){
$data[]=$row['cname'];
}
$back=array(0=>$data);
}
return $back;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
function getGoods(){
try {
$dsn="mysql:host=localhost;dbname=web;charset=utf8";
$sql="select * from itcast_goods";
$pdo=new PDO($dsn,"root",'');
$result=$pdo->query($sql);
if($result){
while($row=$result->fetch(PDO::FETCH_ASSOC)){
$data[]=$row;
}
$back=array(0=>$data);
}
return $back;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
function checkUserPwd($user,$pwd){
try{
$pdo=new PDO("mysql:host=localhost;dbname=web;charset=utf8","root",'');
$sql="select * from itcast_member where user='$user' and pwd='$pwd'";
$stmt=$pdo->prepare("insert into 'itcast_member'(user,pwd)values(?,?)");
$stmt->bindParam(1,$user,PDO::PARAM_STR);
$stmt->bindParam(2,$pwd,PDO::PARAM_STR);
var_dump($stmt->execute());
$result=$pdo->query($sql);
if($result->rowCount()){
return(array(0=>"ok"));
}else{
return(array(1=>'数据不匹配,请确认用户名或密码是否有误'));
}
}catch (PDOException $e){
return(array(1=>$e->getMessage()));
}
}
?>