Ⅰ 如何正确理解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 proct 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 "Proct: $name ($id)";
}
注意,如果查询字段名是别名,则mysql_result中就使用别名.
2、PHP获取显示数据库数据函数之mysql_fetch_row()
array mysql_fetch_row(resource result_set)
从result_set中获取整行,把数据放入数组中.
举例(注意和list 的巧妙配合):
$query = "select id,
name from proct order by name";
$result = mysql_query($query);
while(list($id, $name)
= mysql_fetch_row($result)) {
echo "Proct: $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 proct 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 "Proct: $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 proct order by name";
$result = mysql_query($query);
while($row = mysql_fetch_object
($result)) {
$name = $row->name;
$name = $row->id;
echo "Proct: $name ($id)";
}
以上这些函数就是PHP获取显示数据库数据函数的全部总结。
Ⅱ php 如何获取mysql bigint类型数据
php 获取数据是不需要写类型的,你可以看下边的例子:
$name="张三"; //这种就是字符串
$age=2; //这种就是数字
$other=array("123",22); //数组
像这些,你定义的什么类型,php就可以接受什么类型。不需要特意转
Ⅲ php如何获取数据库信息
代码如下:?View
Code
PHP
include("conn.php");//调用数据库连接文件
echo
"<table
width=572
height=56
border=0
cellspacing=1>
";
//创建html表格
echo
"<tr
bgcolor=#9999FF>";
echo
"<th
width=33
scope=col>id</th>";
echo
"<th
width=100
scope=col>user_name</th>
";
echo
"<th
width=100
scope=col>user_pass</th>
";
echo
"<th
width=100
scope=col>staus</th>";
echo
"<th
width=100
scope=col>insert_time</th>";
echo
"</tr>";
$SQL
=
"select
*
from
user_info";
$query
=
mysql_query($SQL);
//SQL查询语句
while
($row
=
mysql_fetch_array($query)){
//使用while循环mysql_fetch_array()并将数据返回数组
echo
"<tr
onmouseout=this.style.backgroundColor=''
onMouseOver=this.style.backgroundColor='#99CC33'
bgcolor=#CCCCCC>";
echo
"<td>$row[0]</td>";
//输出数组中数据
echo
"<td>$row[1]</td>";
echo
"<td>$row[2]</td>";
echo
"<td>$row[3]</td>";
echo
"<td>$row[4]</td>";
echo
"</tr>";
}
echo
"</table>";输出记录截图
Ⅳ 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,包括二进制文件流也可以。
所以用方法二是最保险的方法
Ⅳ php 获取 sql 数据类型
describetablename;//获取表结构信息
describetablenamefieldname;//获取表的某个字段结构信息
比如:describeusersusername;//获取users表的username字段的结构信息
返回:array(
'Field'=>'username',
'Type'=>'varchar(50)',
'Null'=>'NO',
'Key'=>'UNI',
'Default'=>'',
'Extra'=>''
)
Ⅵ php pdo 如何获取查询数据库
$qian["qian"]=$qian["qian"]->DBSQL("select*fromuserwhere='$name'");
多命名几个变量,你这样 `$qian["qian"]` 用在不同的类型中,容易搞混。
$db=newDatabase();
$result=$db->DBSQL("select*fromuserwhere='$name'limit1");
这里的 $result 应该是个数组。
if($result['qian']==1){
//
}else{
//
}
Ⅶ php如何获取数据库信息
代码如下:?View Code PHP include("conn.php");//调用数据库连接文件 echo "<table width=572 height=56 border=0 cellspacing=1> "; //创建html表格 echo "<tr bgcolor=#9999FF>"; echo "<th width=33 scope=col>id</th>"; echo "<th width=100 scope=col>user_name</th> "; echo "<th width=100 scope=col>user_pass</th> "; echo "<th width=100 scope=col>staus</th>"; echo "<th width=100 scope=col>insert_time</th>"; echo "</tr>"; $SQL = "select * from user_info"; $query = mysql_query($SQL); //SQL查询语句 while ($row = mysql_fetch_array($query)){ //使用while循环mysql_fetch_array()并将数据返回数组 echo "<tr onmouseout=this.style.backgroundColor='' onMouseOver=this.style.backgroundColor='#99CC33' bgcolor=#CCCCCC>"; echo "<td>$row[0]</td>"; //输出数组中数据 echo "<td>$row[1]</td>"; echo "<td>$row[2]</td>"; echo "<td>$row[3]</td>"; echo "<td>$row[4]</td>"; echo "</tr>"; } echo "</table>";输出记录截图
Ⅷ 请问php如何获取当前使用的数据库的类型
啥叫当前使用???你的意思是用PHP程序去监控要执行的PHP程序吗?应该无法做得到的吧,你通过看连接数据库的代码就可以知道使用的是什么数据库啊。
那更好处理啊,你如何判断用什么语法连接数据库就输出什么类型数据库不就行啦
Ⅸ php框架thinkphp3.2怎么读取数据库内容
先找到config.php文件,如图:
<?php
namespaceHomeController;
useThinkController;
{
publicfunctionindex(){
$db=M("show");//实例化show对象
$data=$db->find();//读取一条数据
mp($data);//打印数据
}
}
Ⅹ php支持哪些数据类型
php的数据类型有:1、String字符串型;2、Integer整型;3、Float和Double浮点型;4、Boolean布尔型;5、Array数组;6、Object对象;7、NULL空值等等。