high三个晚上这样好么-JSON&PHP,
high三个晚上这样好么-JSON&PHP,
hi
昨晚上吃火锅去了,对,你没猜错,我就是在成都
今晚有师兄请客,明天有基友请吃火锅,本来该忙忙哒的这一周要连续high三个晚上么(单身研究生狗就是这么容易满足)。所以只好不务正业写写写了(写不动了。。。)
1、JSON
-----简介-----
Javascript Object Notation,一种轻量级的数据交换格式
---
基本语法:四个基本规则
并列的数据之间用逗号分隔;映射用冒号表示;并列数据的集合(数组)用[]表示;映射的集合(对象)用{}表示
比如:北京市的面积为16800平方公里,常住人口1600万人;上海市的面积为6400平方公里,常住人口1800万
用JSON格式表示就是:
[
{"城市":"北京","面积":16800,"人口":1600},
{"城市":"上海","面积":6400,"人口":1800}
]
---
优点:格式简单,易于读写和传输;支持多种语言
缺点:字符集必须是Unicode;语法过于严谨
2、PHP&MySQL
-----php内置mysql函数(二)-----
----四个fetch函数_取结果
---
$query=mysqli_query($con, 'select * from test');
print_r(mysqli_fetch_row($query));
第一个fetch,mysql_fetch_row(),只返回第一行的数据;注意,实际上它每一次读取一行,row by row,所以可以这么全都出来:
$query=mysqli_query($con, 'select * from test');
while($row=mysqli_fetch_row($query)){
print_r($row);
}
而且,如果调用的次数大于行数,将不会输出超过行数的数据,会返回null
Array ( [0] => 1 [1] => Tom ) Array ( [0] => 2 [1] => Tom ) Array ( [0] => 3 [1] => Tom ) Array ( [0] => 4 [1] => Tom ) Array ( [0] => 5 [1] => ???? ) Array ( [0] => 6 [1] => Tom ) Array ( [0] => 7 [1] => ???? )
可以看到返回结果是索引数组
---
mysql_fetch_array()
$arr=mysqli_fetch_array($query);
print_r($arr);
用法类似,结果:
Array ( [0] => 1 [id] => 1 [1] => Tom [name] => Tom )
对比数据库数据
mysql> SELECT * FROM TEST;
+----+------+
| id | name |
+----+------+
| 1 | Tom |
| 2 | Tom |
| 3 | Tom |
| 4 | Tom |
| 5 | ???? |
| 6 | Tom |
| 7 | ???? |
+----+------+
所以,row是取一条数据产生一个索引数组;array默认取一条数据产生一个索引数组和一个关联数组
简单的说,array可以利用键名了,相当方便:
echo $arr['name'];
但是array的速度要慢一点
同时,array还有可选的第二参数,可以选择输出那个/些数组
$arr=mysqli_fetch_array($query,MYSQL_ASSOC);
print_r($arr);
echo $arr['name'];
得到
Array ( [id] => 1 [name] => Tom ) Tom
MYSQL_ASSOC,MYSQL_NUM,MYSQL_BOTH就这么三个参数
---
mysql_fetch_assoc()
基本上就是上一节的东西,输出都一样
---
mysql_fetch_object()
返回的是一个对象
$obj=mysqli_fetch_object($query);
echo $obj->name;
echo "
";
print_r($obj);
结果
Tom
stdClass Object
(
[id] => 1
[name] => Tom
)
同row命令类似,也可以一行一行的输出

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
