mysqli的使用
<?php
/**
数据库连接 **/
$conn=mysqli_connect('localhost:3306','root','root');
if(!$conn){
die("could not connect:".mysqli_error($conn));
}
mysqli_query($conn , "set names utf8");
$sec=mysqli_select_db($conn,'wc');
if(!$sec){
die("error".mysqli_error($conn));
}
$sql="select * from ss";
$retval=mysqli_query($conn,$sql);
if(!$retval){
die("无法读取数据:".mysqli_error($conn));
}
print_r($retval);
while($row=mysqli_fetch_array($retval,MYSQLI_ASSOC)){
echo '<br/>';
print_r($row);
$arr[]=$row;
}
var_dump($arr);
mysqli_free_result($retval);
mysqli_close($conn);
/*3中解析方法
mysqli_fetch_array($retval)查询结果
Array ( [0] => 1 [id] => 1 [1] => 12 [a] => 12 [2] => 34 [b] => 34 [3] => 11 [c] => 11 )
Array ( [0] => 2 [id] => 2 [1] => 65 [a] => 65 [2] => 42 [b] => 42 [3] => 16 [c] => 16 )
Array ( [0] => 3 [id] => 3 [1] => 91 [a] => 91 [2] => 95 [b] => 95 [3] => 93 [c] => 93 )
mysqli_fetch_array($retval,MYSQLI_ASSOC)
Array ( [id] => 1 [a] => 12 [b] => 34 [c] => 11 )
Array ( [id] => 2 [a] => 65 [b] => 42 [c] => 16 )
Array ( [id] => 3 [a] => 91 [b] => 95 [c] => 93 ) mysqli_fetch_assoc($retval)查询结果
Array ( [id] => 1 [a] => 12 [b] => 34 [c] => 11 )
Array ( [id] => 2 [a] => 65 [b] => 42 [c] => 16 )
Array ( [id] => 3 [a] => 91 [b] => 95 [c] => 93 )
//mysqli_fetch_row($retval)
Array ( [0] => 1 [1] => 12 [2] => 34 [3] => 11 )
Array ( [0] => 2 [1] => 65 [2] => 42 [3] => 16 )
Array ( [0] => 3 [1] => 91 [2] => 95 [3] => 93 )
//mysqli_fetch_field($retval)
stdClass Object ( [name] => id [orgname] => id [table] => ss [orgtable] => ss [def] => [db] => wc [catalog] => def [max_length] => 1 [length] => 11 [charsetnr] => 63 [flags] => 49667 [type] => 3 [decimals] => 0 )
stdClass Object ( [name] => a [orgname] => a [table] => ss [orgtable] => ss [def] => [db] => wc [catalog] => def [max_length] => 2 [length] => 11 [charsetnr] => 63 [flags] => 32768 [type] => 3 [decimals] => 0 )
stdClass Object ( [name] => b [orgname] => b [table] => ss [orgtable] => ss [def] => [db] => wc [catalog] => def [max_length] => 2 [length] => 11 [charsetnr] => 63 [flags] => 32768 [type] => 3 [decimals] => 0 )
stdClass Object ( [name] => c [orgname] => c [table] => ss [orgtable] => ss [def] => [db] => wc [catalog] => def [max_length] => 2 [length] => 11 [charsetnr] => 63 [flags] => 32768 [type] => 3 [decimals] => 0 )
*/
mysqli的使用的更多相关文章
- 比Mysqli操作数据库更简便的方式 。PDO
下面来说一下PDO 先画一张图来了解一下 mysqli是针对mysql这个数据库扩展的一个类 PDO是为了能访问更多数据库 如果出现程序需要访问其他数据库的话就可以用PDO来做 PDO数据访问抽象层1 ...
- PHP 数据库连接工具类(MySQLI函数包装)
====================mysql===================== <?php class mysql { private $mysqli; private $resu ...
- php mysqli mysqli_query() mysqli_real_query()
2016年11月26日 15:22:27 星期六 场景: PHP从mysql中读取数据 1. 一次性读取所有数据返给PHP 2. 每次循环只读取一掉记录 数据量小的时候可以使用第一种方法, 数据量很大 ...
- mysqli操作数据库
1 连接数据库:可以使用对象或函数来连接(我们这里主要用mysqli对象,附带着函数连接) //创建mysqli对象(也可以叫做资源句柄) $_mysqli = new mysqli(); //连接数 ...
- php的mysql\mysqli\PDO(二)mysqli
原文链接:http://www.orlion.ga/1147/ mysqli有面向对象风格和面向过程风格,个人感觉还是用面向对象风格比较好(毕竟是面向对象) 1.mysqli::_construct( ...
- PHP使用mysqli扩展库实现增删改查(面向对象版)
mysqli扩展库是mysql扩展库的改进版本,在mysql扩展库的基础上提高了稳定性和效率,mysqli扩展库有两套东西,一套就是面向过程的mysqli另一套是面向对象的mysqli.操作方式大体和 ...
- 解决 Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in
转载 php 5个版本,5.2.5.3.5.4.5.5,怕跟不上时代,新的服务器直接上5.5,但是程序出现如下错误:Deprecated: mysql_connect(): The mysql ext ...
- PHP mysql与mysqli事务详解
官方对PHP连接到MySQL数据库服务器的三种主要的API简介如下: http://php.net/manual/zh/mysqli.overview.php PHP mysql与mysqli事务详解 ...
- mysql、mysqli、PDO一句话概括比较
mysql.mysqli.PDO一句话概括比较 1 mysql扩展 (注:原始的,较差) 2 mysqli扩展(面向过程式) (注:比上面多了更多功能) 3 mysqli扩展(面向对象式) (注:比上 ...
- mysqli链接数据库:面向对象
$mysqli = new mysqli('localhost','root','123','test');//检查连接是否成功if (mysqli_connect_error()){ //注意mys ...
随机推荐
- linux内核中的vgaarb是什么?
答: vga仲裁器(vga arbiter),是内核中的一个模块
- sudo用法记录
使用root用户,visudo命令(实际是编辑/etc/sudoers文件),用法和vim一样,末行模式:wq退出,如还有提示,使用大写"Q"保存退出,小写"e" ...
- Unity3D学习笔记(三十一):Xlua(1)
Xlua:腾讯研发,开源免费 配置:文件解压,拷贝到Unity项目里 注意:Xlua文件夹不许移动,不许重命名 运行Xlua: 1.引用命名空间 2.创建虚拟机 3.运行lua语句 4.不需要 ...
- Python多线程爬虫
前言 用上多线程,感觉爬虫跑起来带着风 运行情况 爬取了9万多条文本记录,耗时比较短,一会儿就是几千条 关键点 多个线程对同一全局变量进行修改要加锁 # 获取锁,用于线程同步 threadLock.a ...
- 3、My Scripts
.用for循环批量修改文件扩展名(P240) .使用专业改名命令rename来实现 .通过脚本实现sshd.rsyslog.crond.network.sysstat服务在开机时自动启动(P244) ...
- border:none和border:0的区别
C:当定义border:none时,表示无边框样式,浏览器并不会对边框进行渲染,也就没有实际的宽度: D:定义边框时,除了设置宽度外,还必须设置边框的样式才能显示出来. border:0;浏 ...
- Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分+前缀
D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...
- python中常用的模块二
一.序列化 指:在我们存储数据的时候,需要对我们的对象进行处理,把对象处理成方便存储和传输的数据格式,这个就是序列化, 不同的序列化结果不同,但目的是一样的,都是为了存储和传输. 一,pickle.可 ...
- DLL.LoadLibrary失败(126)
1.LoadLibrary 返回 NULL,GetLastError 显示的是 错误码126,msdn上是这样的: ERROR_MOD_NOT_FOUND 126 (0x7E) The specifi ...
- Linux下的JDK和OpenJDK有什么具体的区别
OpenJDK是JDK的开放原始码版本,以GPL(General Public License)协议的形式放出(题主提到的open就是指的开源).在JDK7的时候,OpenJDK已经作为JDK7的 ...