简体   繁体   English

将mysql结果显示为对象?

[英]Displaying mysql results as an object?

If I have a database with the structure: 如果我的数据库结构如下:

___id_____|____value____
   1      |    value1
   2      |    value2
   3      |    value3

How can I pull data from this MySQL database in PHP and have it formatted like this: 我该如何从PHP的MySQL数据库中提取数据并进行格式化,如下所示:

Array ( [0] => stdClass Object ( [id] => 1 [value] => value1 ) [1] => stdClass Object ( [id] => 2 [value] => value2 ) [2] => stdClass Object ( [id] => 3 [value] => value3 ) )

You can use the mysql_fetch_object() function instead of mysql_fetch_array() and manually create new objects. 您可以使用mysql_fetch_object()函数代替mysql_fetch_array()并手动创建新对象。

Read more about it here: http://php.net/manual/en/function.mysql-fetch-object.php 在这里阅读更多有关它的信息: http : //php.net/manual/en/function.mysql-fetch-object.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM