今天我还在继续学习PHP与MySQL应用开发的相关知识,今天想用PHP跟MySQL数据库交互,看了Mambo及Mediawiki的相关源代码,感觉都是直接用SQL语句进行数据操作,因为数年前,我在速达上海分公司做产品时大量采用了存储过程,所以也就想应用一下MySQL的存储过程,经过查看MySQL及PHP的相关文档,我用mysqli及mysqli_stmt_bind_param进行了验证,以下是MySQL创建数据库及生成表与存储过程的命令:
create database `openshop` default character set utf8 collate utf8_general_ci;然后使用了以下PHP验证代码:
GRANT ALL PRIVILEGES ON openshop.* TO 'os'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
use openshop;
CREATE TABLE /*_*/users (
user_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
user_name varchar(255) binary NOT NULL default ''
);
delimiter //
CREATE PROCEDURE insert_user(IN name varchar(255))
BEGIN
insert into users(user_name) values(name);
END
//
<?php通过MySQL客户端查询结果如下图所示:
$mysqli = new mysqli("localhost", "os", "password", "openshop");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$city = "hah'a";
/* create a prepared statement */
if ($stmt = $mysqli->prepare("call insert_user(?)")) {
/* bind parameters for markers */
$stmt->bind_param("s", $city);
/* execute query */
$stmt->execute();
/* close statement */
$stmt->close();
echo $city;
}
/* close connection */
$mysqli->close();
?>
其实这么做大家也知道,只有一个好处,那就是可以避免使用PHP生成表插入数据时对特殊字符“'”的处理。今天真是一切顺利,明天继续。
6 条评论:
ugg sale
ugg uk
ugg boots sale
ugg boots outlet store
uggs sale
north face outlet
isabel marant sneakers
discount ugg boots
uggs outlet online
ugg boots uk
fendi bags
cheap ugg boots
ugg boots sale
tiffany and co jewelry
balenciaga outlet
uggs on sale uk
nike high heels
longchamp outlet store
discount ugg boots
cheap kevin durant shoes
ugg sale
ugg boots on sale
uggs black friday
parajumper outlet
uggs outlet
ugg boots sale
ugg boots for cheap
uggs clearance
discount uggs
cheap ugg boots
ugg boots for kids
ugg boots sale uk
ugg boots outlet
ugg uk
ugg boots uk
Air Jordans Shoes
Air Jordan Pas Cher
Air Jordan Retro Shoes
Air Jordan Femme
Nike Air Jordan
Nike Free Shoes
Cheap Beats Headphones
Kyrie Irving Shoes
New KD 7
Kobe 9 Shoes
lebron 12
cheap kd 7
Air Jordan Retro Shoes
CHEAP KOBE 9
Jordan Pas Cher
Beats By Dre For Sale
KD 7 Shoes
kobe 9 christmas
lbj shoes
Kobe 9 Elite
Kobe 9 Low
kobe 9 elite pas cher
Zapatillas Air Jordan
Casque Beats Pas Cher
2016-05-07keyun
ralph lauren home
ray ban eyeglasses
hollister clothing store
coach outlet clearance
louis vuitton outlet online
ghd hair straighteners
concords 11
coach outlet store
instyler
louis vuitton handbags
ray ban sunglasses wholesale
ray ban sunglasses
reb christian louboutin
air jordan shoes
adidas originals store
louis vuitton bags
coach outlet
ray bans
air max 95
louboutin shoes
coach outlet
ray ban sunglasses
polo ralph lauren
christian louboutin outlet
coach factory outlet online
christian louboutin shoes
hollister shirts
kd 8
michael kors handbags
kobe 8
ray ban outlet
louis vuitton handbags
michael kors bags
air jordan homme
louis vuitton outlet online
hollister clothing
fitflop shoes
cheap ray ban sunglasses
michael kors outlet online
ray ban sunglasses
giuseppe zanotti
abercrombie and fitch
ugg boots
coach factory outlet
uggs on sale
uggs outlet
ugg boots
canada goose outlet
gucci outlet online
201612.15wengdongdong
polo ralph lauren outlet
cheap pandora jewelry
instyler max
ralph lauren outlet
tory burch outlet
michael kors outlet online
nike roshe run
michael kors bags
adidas nmd
nike outlet
2017.3.13xukaimin
houston rockets jerseys
polo ralph lauren outlet online
louis vuitton
cheap oakley sunglasses
burberry outlet online
coach outlet
ed hardy sale
new york yankees jerseys
louboutin uk
adidas nmd
20170315huazhen
发表评论