成都创新互联网站制作重庆分公司

php获取数据后处理,php获取数据后处理结果

如何正确理解PHP获取显示数据库数据函数

1、PHP获取显示数据库数据函数之 mysql_result()

目前成都创新互联公司已为近千家的企业提供了网站建设、域名、网络空间、网站托管、服务器租用、企业网站设计、会泽网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

mixed mysql_result(resource result_set, int row [,mixed field])

从result_set 的指定row 中获取一个field 的数据. 简单但是效率低.

举例:

$link1 = @mysql_connect("server1", 

"webuser", "password") 

or die("Could not connect 

to mysql server!");

@mysql_select_db("company") 

or die("Could not select database!");

$query = "select id, name 

from product order by name"; 

$result = mysql_query($query);

$id = mysql_result($result, 0, "id");

$name = mysql_result($result, 0, "name");

mysql_close();

注意,上述代码只是输出结果集中的第一条数据的字段值,如果要输出所有记录,需要循环处理.

for ($i = 0; $i = mysql_num_rows($result); $i++)

{

$id = mysql_result($result, 0, "id");

$name = mysql_result($result, 0, "name");

echo "Product: $name ($id)";

}

注意,如果查询字段名是别名,则mysql_result中就使用别名.

2、PHP获取显示数据库数据函数之mysql_fetch_row()

array mysql_fetch_row(resource result_set)

从result_set中获取整行,把数据放入数组中.

举例(注意和list 的巧妙配合):

$query = "select id, 

name from product order by name"; 

$result = mysql_query($query);

while(list($id, $name) 

= mysql_fetch_row($result)) {

echo "Product: $name ($id)";

}

3、PHP获取显示数据库数据函数之mysql_fetch_array()

array mysql_fetch_array(resource result_set [,int result_type])

mysql_fetch_row()的增强版.

将result_set的每一行获取为一个关联数组或/和数值索引数组.

默认获取两种数组,result_type可以设置:

MYSQL_ASSOC:返回关联数组,字段名=字段值 

MYSQL_NUM:返回数值索引数组.

MYSQL_BOTH:获取两种数组.因此每个字段可以按索引偏移引用,也可以按字段名引用.

举例:

$query = "select id,

name from product order by name";

$result = mysql_query($query);

while($row = mysql_fetch_array

($result, MYSQL_BOTH)) { 

$name = $row['name'];

//或者 $name = $row[1];

$name = $row['id'];

//或者 $name = $row[0];

echo "Product: $name ($id)";

}

4、PHP获取显示数据库数据函数之mysql_fetch_assoc()

array mysql_fetch_assoc(resource result_set)

相当于 mysql_fetch_array($result, MYSQL_ASSOC)

5、PHP获取显示数据库数据函数之mysql_fetch_object()

object mysql_fetch_object(resource result_set) 

和mysql_fetch_array()功能一样,不过返回的不是数组,而是一个对象.

举例:

$query = "select id, name 

from product order by name";

$result = mysql_query($query); 

while($row = mysql_fetch_object

($result)) {

$name = $row-name;

$name = $row-id;

echo "Product: $name ($id)";

}

以上这些函数就是PHP获取显示数据库数据函数的全部总结。

php获取post数据

方法1、最常见的方法是:$_post['fieldname'];

说明:只能接收content-type:

application/x-www-form-urlencoded提交的数据

解释:也就是表单post过来的数据

方法2、file_get_contents("php://input");

说明:

允许读取

post

的原始数据。

$http_raw_post_data

比起来,它给内存带来的压力较小,并且不需要任何特殊的

php.ini

设置。

php://input

不能用于

enctype="multipart/form-data"。

解释:

对于未指定

content-type

的post数据,则可以使用file_get_contents(“php://input”);来获取原始数据。

事实上,用php接收post的任何数据都可以使用本方法。而不用考虑content-type,包括二进制文件流也可以。

所以用方法二是最保险的方法

方法3、$globals['http_raw_post_data'];

说明:

总是产生

$http_raw_post_data

变量包含有原始的

post

数据。

此变量仅在碰到未识别

mime

类型的数据时产生。

$http_raw_post_data

对于

enctype="multipart/form-data"

表单数据不可用

如果post过来的数据不是php能够识别的,可以用

$globals['http_raw_post_data']来接收,

比如

text/xml

或者

soap

等等

解释:

$globals['http_raw_post_data']存放的是post过来的原始数据。

$_post或$_request存放的是

php以key=value的形式格式化以后的数据。

但$globals['http_raw_post_data']中是否保存post过来的数据取决于centent-type的设置,即post数据时

必须显式示指明content-type:

application/x-www-form-urlencoded,post的数据才会存放到

$globals['http_raw_post_data']中

PHP关于获取二进制数据流转换为文件的方法

$content = $_POST['data'];

$fp = fopen('/tmp/newfile.bin','w');

fwrite($fp,$content);

以上例子是在data参数上传二进制,并保存到/tmp/newfile.bin中,解析json用json_decode,然后把二进制的那个值赋给content就可以

php获取了数据,传输数据到MySQL没有报错,但MySQL数据库无数据?

额 不好意思现在才看到 你看啊 你插入的字段是id这个id应该是int类型吧 然后你$a='test’还有你的是insert返回的应该是true 或者false 不应该是一个资源

望采纳!

php中如何用tp实现去获取数据库的内容,然后显示到前端的页面?

先建立数据表并插入数据

这里假设已经存在user表,并且有一条数据id:1,name:admin

那么读取这个数据的过程是

$data = M('User')-select();

$this-assign('user',$data);

模板中的调取代码是

volist name="user" id="v"

用户名:{$v.name} ID:{$v.id}

/volist

php获取服务器端数据得到json后转换数组始终为null是怎么回事

你可以将你获取到的json数据贴上来看看.出现null绝大多数是因为格式有误引起的。

但是有时候也会由于编码原因(比如,远程获取其它链接地址的json数据)


本文标题:php获取数据后处理,php获取数据后处理结果
文章地址:http://cxhlcq.com/article/hopise.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部