php和mysql交互 面向对象
不返回结果集 <?php
//使用对象属性和方法来插入数据
header('Content-type:text/html;carset=utf8');
$con=new mysqli('localhost','root','123456','t3',3306);
$str='insert into tech values (9,"刘海波",132789)';
if($con->connect_error){
$con->connect_error();
}
$con->set_charset('utf8');
if($con->query($str)==true){
echo '插入数据成功';
}else{
echo 'ERRPR'.$str.$con->error;
} $con->close(); ?>
返回结果集
<?php
//使用对象属性和方法来插入数据
header('Content-type:text/html;carset=utf8');
$con=new mysqli('localhost','root','123456','t3',3306);
$str='select * from tech';
if($con->connect_error){
$con->connect_error();
}
$con->set_charset('utf8');
$result=$con->query($str);
//fetch_assoc 返回数组
while($jieguo=$result->fetch_assoc()){ echo $jieguo['id'].'-------'.$jieguo['name'].'---------'.$jieguo['pwd'].'--------'.'<br>';
} $con->close(); ?>
预处理机制
<?PHP
header('Content-type:text/html;charset=utf8');
$con=new mysqli('localhost','root','123456','t3');
if($con->connect_error){
die('连接失败'.$con->connect_error);
}
$con->set_charset('utf8');
$query='insert into tech values (?,?,?)';
//预备sql处理函数 返回一个数据库类型对象
$stmt=$con->prepare($query);
$stmt->bind_param('isi',$fid,$fname,$fpwd);
$fid=10;
$fname="祁筱以";
$fpwd=456852;
$stmt->execute();
echo '插入成功';
//释放类型数据库对象结果集
$stmt->free_result();
//关闭数据库连接
$con->close();
?>
预处理机制返回结果
<?PHP
header('Content-type:text/html;charset=utf8');
$con=new mysqli('localhost','root','123456','t3');
if($con->connect_error){
die('连接失败'.$con->connect_error);
}
$con->set_charset('utf8');
$query='select * from tech where id>?';
//预备sql处理函数 返回一个预编译的sql对象
$stmt=$con->prepare($query);
$stmt->bind_param('i',$fid);
$fid=1;
$stmt->execute();
//预编译sql对象绑定结果
$stmt->bind_result($id,$name,$pwd);
while($stmt->fetch()){
echo "{$id}->{$name}->{$pwd}<br>";
}
$stmt->free_result();
//关闭数据库连接
$con->close();
?>
php和mysql交互 面向对象的更多相关文章
- mysql交互协议解析——mysql包基础数据、mysql包基本格式
mysql交互协议是开发mysql周边组件常用的协议,如JDBC,libmysql等等. 在此我们要认识到mysql交互协议其实是半双工的交互协议,至于为什么,这里就先挖个小坑,以后再填. 在探讨my ...
- Nodejs学习笔记(四)--- 与MySQL交互(felixge/node-mysql)
目录 简介和安装 测试MySQL 认识一下Connection Options MYSQL CURD 插入 更新 查询 删除 Nodejs 调用带out参数的存储过程,并得到out参数返回值 结束数据 ...
- Shell基础:Shell和Mysql交互
通过命令行和Mysql交互 [root]#mysql -uroot -p123 -e "show databases" -e: execute: 执行数据库命令 通过脚本和数据 ...
- Hadoop集群(第10期)_MapReduce与MySQL交互
2.MapReduce与MySQL交互 MapReduce技术推出后,曾遭到关系数据库研究者的挑剔和批评,认为MapReduce不具备有类似于关系数据库中的结构化数据存储和处理能力.为此,Google ...
- 与MySQL交互(felixge/node-mysql)
目录 简介和安装 测试MySQL 认识一下Connection Options MYSQL CURD 插入 更新 查询 删除 Nodejs 调用带out参数的存储过程,并得到out参数返回值 结束数据 ...
- Nodejs学习笔记(四)—与MySQL交互(felixge/node-mysql)
简介和安装 Node.js与MySQL交互操作有很多库,具体可以在 https://www.npmjs.org/search?q=mysql 查看. 我选择了felixge/node-mysql,用 ...
- python3与mysql交互:pymysql
python3与mysql交互 1.安装pymysql模块 pip3 install pymysql3 2.pymysql的简单使用: # /usr/bin/env python3 import py ...
- 第一节、Alex 讲解 python+mysql 交互;
Python Mysql 交互 A.Alex 的语法展示: import MySQLdb try: conn=MySQL.connect(host='localhost',user='ro ...
- Python与Mysql交互
#转载请联系 在写内容之前,先放一张图,bling- 这张图算是比较详细的表达出了web开发都需要什么.用户访问网页,就是访问服务器的网页文件.这些网页文件由前端工程师编写的.服务器通常用nginx/ ...
随机推荐
- 运维笔记--Ubuntu离线安装jdk1.8(JDK8)Java环境
Ubuntu离线环境安装jdk1.8 系统版本:Ubuntu16.04 其他Ubuntu版本安装类似 Jdk版本:8 1. 下载相应离线软件包 Jdk oracle官方下载地址:https://www ...
- Tesserac初探
安装Tesseract Windows 系统 下载可执行安装文件https://code.google.com/p/tesseract-ocr/downloads/list安装.或者https://d ...
- CobaltStrike3.14破解
原文发布在:https://bithack.io/forum/310 8月6日已更新 之前发的是5月2号破解的,并且官方作者的exit暗桩没有去掉.看到很多人用此版本遇到问题,抽空修复了下bug.此版 ...
- Heartbeat took longer than "00:00:01" at "09/06/2019 05:08:08 +00:00".
.netcore在k8s+docker+linux,部署后,偶尔会报这样的警告 Warn:Microsoft.AspNetCore.Server.KestrelHeartbeat took longe ...
- 【错误解决】UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 840: illegal multibyte sequence
原文来源:https://www.zhihu.com/question/22699590 编码问题错误,读入文件的时候指定编码即可. with open(fname, encoding='utf-8' ...
- Failed to open .vcf.gz: could not load index
这类报错在我使用bcftools index file.vcf.gz进行index出现的. 解决办法是换用tabix进行index,命令为tabix -p vcf file.vcf.gz. 用tabi ...
- 【tensorflow-v2.0】如何查看模型的输入输出流的属性
操作过程: 1. 查看mobilenet的variables loaded = tf.saved_model.load('mobilenet') print('MobileNet has {} tra ...
- [LeetCode] 334. Increasing Triplet Subsequence 递增三元子序列
Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...
- 1-2docker-基本的使用
1.Docker 官⽅提供了⼀个公共的镜像仓库 https://hub.docker.com 2.获取镜像 docker pull [选项] [Docker Registry 地址[:端⼝]/]仓库名 ...
- python从写定时器学习Thread
目录 python从写定时器学习Thread Timer 对象 粗陋的循环定时器 更 pythonic 循环定时器 FAQ python从写定时器学习Thread python 如何写一个定时器,循环 ...