转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> MySql >> 正文
MySQL数据库函数详解(4)         ★★★★

MySQL数据库函数详解(4)

作者:闵涛 文章来源:闵涛的学习笔记 点击数:648 更新时间:2009/4/22 20:08:59
(13) object mysql_fetch_object(int result_id [, int result_typ]);
本函式用来将查询结果 result 拆到物件变数中。使用方法和 mysql_fetch_array() 几乎相同,不同的地方在于本函式传回资料是物件而不是阵列。若 result 没有资料,则传回 false 值。另外值得注意的地方是,取回的物件资料的索引只能是文字而不能用数字,这是因为物件的特性。物件资料的特性中所有的属性(property) 名称都不能是数字,因此只好乖乖使用文字字串当索引了。参数 result_typ是一个常数值,有以下几种常数 MYSQL_ASSOC、MYSQL_NUM 与 MYSQL_BOTH。关于速度方面,本函式的处理速度几乎和mysql_fetch_row() 及 mysql_fetch_array() 二函式差不多,要用哪个函式还是看使用的需求决定。

<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("stamp_db") or die("Could not select database");
$query="SELECT last_name,first_name FROM president";
$result=mysql_query($query) or die("Query failed");
while($row=mysql_fetch_object($result))
printf("%s %s<BR>
",$row->last_name,$row->first_name);
mysql_free_result($result);
?>

(14) array mysql_fetch_row(int result);
作为一个数组返回给定结果集的下一行,如果没有更多的行,则返回假。列值可作为数组元素访问,在0到mysql_num_fields()-1范围内使用列索引。

<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("stamp_db") or die("Could not select database");
$query="SELECT last_name,first_name FROM president";
$result=mysql_query($query) or die("Query failed");
while($row=mysql_fetch_row($result))
printf("%s %s<BR>
",$row[0],$row[1]);
mysql_free_result($result);
?>

(15) string mysql_field_name(int result, int field_index);
返回结果集的给定列的名称。
col_num 的范围为0到mysql_num_fields()-1.

<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("stamp_db") or die("Could not select database");
$query="SELECT * FROM president";
$result=mysql_query($query) or die("Query failed");
for($i=0;$i<mysql_num_fields($result);$i++)
{
printf("Name of column %d:",$i);
$name=mysql_field_name($result,$i);
if(!$name)
print("No name available<BR>
");
else
print("$name<BR>
");
}
?>


(16) int mysql_field_seek(int result, int field_offset);
为随后的mysql_fetch_field()调用设置索引。发布没有明确列号的mysql_fetch_field()的下一次调用,将返回列col_num的信息。如果搜索成功,返回真,否则返回假。
col_num的范围为0到mysql_num_fields()-1.

<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
mysql_select_db("stamp_db") or die("Could not select database");
$query="SELECT * FROM president";
$result=mysql_query($query) or die("Query failed");
for($i=0;$i<mysql_num_fields($result);$i++)
{
printf("Information for column %d:<BR>
",$i);
if(!mysql_field_seek($result,$i))
{
print("Cannot seek to colum<BR>
");
continue;
}
$meta=mysql_fetch_field($result,$i);
if(!$meta)
{
print("No information available<BR>
");
continue;
}
print("<PRE>
");
printf("blob: %s
",$meta->blob);
printf("max_length: %s
",$meta->max_length);
printf("multiple_key: %s
",$meta->multiple_key);
printf("name: %s
",$meta->name);
printf("not_null: %s
",$meta->not_null);
printf("numeric: %s
",$meta->numeric);
printf("primary_key: %s
",$meta->primary_key);
printf("table: %s
",$meta->table);
printf("type: %s
",$meta->type);
printf("unique_key: %s
",$meta->unique_key);
printf("unsigned: %s
",$meta->unsigned);
printf("zerofill: %s
",$meta->zerofill);
print("</PRE>
");
}
?>


[Web开发]ASP获取当月天数的函数  [Web开发]PHP获取当前url路径的函数及服务器变量:QUERY_STR…
[Web开发]php删除文件函数详解  [Web开发]php删除文件函数详解
[Web开发]PHP的sleep函数关闭窗口后是否继续运行?  [Web开发]file_get_contents函数不能使用的解决方法详解
[办公软件]Excel函数的使用方法(手工输入介绍)  [办公软件]EXCEL函数大全七
[办公软件]EXCEL函数大全六  [办公软件]EXCEL函数大全五
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台