php 操纵 mysql 预处理惩罚(未完待续)
添加时间:2013-5-9 点击量:
因为本地 PHP 版本过底,没办法进行完全的测试
¥host = localhost;
¥user = root;
¥password = ;
¥dbname = cmstop;
¥mysqli = new mysqli(¥host, ¥user, ¥password, ¥dbname) or exit(无法连接到mysql:.¥mysqli->connect_error);
¥sql = SELECT CURRENT_USER(); SELECT FROM `db_setting` LIMIT 5;;
if (¥mysqli->multi_query(¥sql)){//多条查询
do{
if(¥result = ¥mysqli->store_result()){//若是还有还成果集,取当前的一个成果集返回
while(¥row = ¥result->fetch_row()){//取一笔记录
echo ¥row[0];
}
¥result->free();//当此成果集中无记录时,开释
}
if(¥mysqli->more_results()){//若是还有一个成果集,则输出分隔线
echo <hr />;
}
}while(¥mysqli->next_result());
}
//预处理惩罚
¥sql = SELECT `app`,`var` FROM `db_setting` WHERE `app`=? LIMIT 5;
¥app = article;
¥stmt = ¥mysqli->stmt_init();
if(¥stmt->prepare(¥sql)) {
¥stmt->bind_param(s, ¥app);
¥stmt->execute();//履行查询
¥stmt->bind_result(¥field1, ¥field2); //生成两个字段的成果集
while (¥stmt->fetch()) {
echo <br/>, ¥field1, => , ¥field2;
}
echo<hr/>;
¥app = guestbook;
¥stmt->execute();//履行查询
¥result = ¥stmt->get_result(); //生成两个字段的成果集
while (¥row = ¥result->fetch_array(MYSQLI_NUM)){
echo ¥row[0], => ,¥row[1];
}
¥stmt->close();
}
¥mysqli->close();
真正的心灵世界会告诉你根本看不见的东西,这东西需要你付出思想和灵魂的劳动去获取,然后它会照亮你的生命,永远照亮你的生命。——王安忆《小说家的十三堂课》
因为本地 PHP 版本过底,没办法进行完全的测试
¥host = localhost;
¥user = root;
¥password = ;
¥dbname = cmstop;
¥mysqli = new mysqli(¥host, ¥user, ¥password, ¥dbname) or exit(无法连接到mysql:.¥mysqli->connect_error);
¥sql = SELECT CURRENT_USER(); SELECT FROM `db_setting` LIMIT 5;;
if (¥mysqli->multi_query(¥sql)){//多条查询
do{
if(¥result = ¥mysqli->store_result()){//若是还有还成果集,取当前的一个成果集返回
while(¥row = ¥result->fetch_row()){//取一笔记录
echo ¥row[0];
}
¥result->free();//当此成果集中无记录时,开释
}
if(¥mysqli->more_results()){//若是还有一个成果集,则输出分隔线
echo <hr />;
}
}while(¥mysqli->next_result());
}
//预处理惩罚
¥sql = SELECT `app`,`var` FROM `db_setting` WHERE `app`=? LIMIT 5;
¥app = article;
¥stmt = ¥mysqli->stmt_init();
if(¥stmt->prepare(¥sql)) {
¥stmt->bind_param(s, ¥app);
¥stmt->execute();//履行查询
¥stmt->bind_result(¥field1, ¥field2); //生成两个字段的成果集
while (¥stmt->fetch()) {
echo <br/>, ¥field1, => , ¥field2;
}
echo<hr/>;
¥app = guestbook;
¥stmt->execute();//履行查询
¥result = ¥stmt->get_result(); //生成两个字段的成果集
while (¥row = ¥result->fetch_array(MYSQLI_NUM)){
echo ¥row[0], => ,¥row[1];
}
¥stmt->close();
}
¥mysqli->close();
真正的心灵世界会告诉你根本看不见的东西,这东西需要你付出思想和灵魂的劳动去获取,然后它会照亮你的生命,永远照亮你的生命。——王安忆《小说家的十三堂课》