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 ...
随机推荐
- sudo中的 各类授权 名称包含的操作 权限命令?
sudo是 do something as super user: 或者说: as Super User Do something: 就是 为 "非根用户赋予根用户的权限" 使用 ...
- Docker 编排工具Rancher 1.6.18
使用docker获取rancher [root@localhost /]# docker pull rancher/server:stable [root@localhost /]# docker i ...
- JWT、OAUTH2与SSO资料补充
JWT: 阮一峰:http://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.html https://blog.csdn.net/q ...
- Java 实现一个自己的显式锁Lock(有超时功能)
Lock接口 package concurency.chapter9; import java.util.Collection; public interface Lock { static clas ...
- multiple definition of `qMain(int, char**)'
QT C++ 我上一分钟运行地好好的,下一分钟就无法通过编译了.查了半天发现在IDE自动生成的项目文件.pro中 main竟然包含了两遍.我对这表示很无语,我完全是通过IDE来操作,却产生一些我不易察 ...
- 4、python内置类型(0529)
支持运算:索引,切片,min(), max(), len()等 支持操作:对象的自有的方法 对字符串操作的内置方法获取:str. //敲tab键补全 获取某个内建命令的属性和方法列表:dir( ...
- 「BZOJ2153」设计铁路 - 斜率DP
A省有一条东西向的公路经常堵车,为解决这一问题,省政府对此展开了调查. 调查后得知,这条公路两侧有很多村落,每个村落里都住着很多个信仰c教的教徒,每周日都会开着自家的车沿公路到B地去"膜拜& ...
- 2nd,Python基础2——02
1 列表.元组操作 列表可以对数据实现最方便的存储.修改等操作 names = ['Jack', 'Leon','Eric'] 通过下表访问列表中的元素,下标从0开始计数 names = ['Jack ...
- Http_code码
_codes = { : (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: (: ...
- 实现一个优先级队列,每次pop 返回优先级最高的元素
demo1 实现一个按优先级排序的队列, 并且在这个队列上面每次 pop 操作总是返回优先级最高的那个元素 import heapq class PriorityQueue: def __init__ ...