今日是:
  小新技术网 -=> 数据库 -=> Mysql库 -=> 正文

MySQL数据库函数详解(3)

作者:[本站编辑] 来源:[本站] 浏览:[] 评论:[]  【字体:
(9) string mysql_error(int [link_id]);
对于给定的连接,返回含有最近返回状态的与MySQL相关的函数的错误消息字符串。空值意味着未出现错误。

<?php
$link=mysql_pconnect("localhost","sunsoft","suixiang") or die("Could not connect");
print("Connected successfully");
$query="SELECT * FROM president";
$result=mysql_query($query) or die("query failed,error message=".mysql_error());
?>

(10)array mysql_fetch_array(int result, int [result_typ]);
本函式用来将查询结果 result 拆到阵列变数中。若 result 没有资料,则传回 false 值。而本函式可以说是 mysql_fetch_row() 的加强函式,除可以将传回列及数字索引放入阵列之外,还可以将文字索引放入阵列中。若是好几个传回栏位都是相同的文字名称,则最后一个置入的栏位有效,解决方法是使用数字索引或者为这些同名的栏位 (column) 取别名 (alias)。值得注意的是使用本函式的处理速度其实不会比mysql_fetch_row() 函式慢,要用哪个函式还是看使用的需求决定。参数 result_typ 是一个常数值,有以下几种常数 MYSQL_ASSOC、MYSQL_NUM 与 MYSQL_BOTH。
使用范例


<?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_array($result))
{
printf("%s %s<BR>
",$row[0],$row[1]);
printf("%s %s<BR>
",$row["last_name"],$row["first_name"]);
}
mysql_free_result($result);

?>


(11) object mysql_fetch_field(int result [,int col_num]);
返回结果集中给定列的相关元数据信息,如果没有这样的列,则返回假。如果省略col_num,则对mysql_fetch_field()的后继调用返回结果集后续列的信息。如果不再有剩余的列。则返回值为假。如果指定了col_num,则其取值范围为0到mysql_num_fields()-1。在此情况下,mysql_num_fields()返回给定列的相关信息,如果col_num超出范围,返回假。
<?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);
$meta=mysql_fetch_field($result);
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>
");
}
?>

(12) array mysql_fetch_lengths(int result);
本函式将 mysql_fetch_row() 处理过的最后一列资料的各栏位资料最大长度放在阵列变数之中。若执行失败则传回 false 值。传回阵列的第一笔资料索引值是 0。

<?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" or die("Query failed");
$row_num=0;
while(mysql_fetch_row($result))
{
++$row_num;
printf("Lengths of values in row %d:<BR>
",$row_num);
$len=mysql_fetch_lengths($result);
if(!$len)
{
print("No information available<BR>
");
break;
}
print("<PRE>
");
for($i=0;$i<mysql_num_fields($result);$i++)
printf("Column %d: %s
",$i,$len[$i]);
print("</PRE>
");
}
?>

下一篇:高手是怎样炼成的:精妙SQL语句介绍
上一篇:MySQL数据库函数详解(4)
IP查询、IP签名
打印 】【 收藏 】【 评论 】【 推荐
相关文章 栏目推荐文章 栏目热门文章
 普通文章 MySQL数据库函数详解(4) 
 普通文章 MySQL数据库函数详解(2) 
 推荐文章 MySQL数据库函数详解(1) 
 普通文章 MySQL数据库函数详解(5) 
 普通文章 MySQL数据库函数详解(4) 
 推荐文章 MySQL数据库函数详解(1) 
 推荐文章 高手是怎样炼成的:精妙SQL语句介绍.. 
 推荐文章 Mysql的常用命令 
 普通文章 MySQL管理员指南 
 推荐文章 高手是怎样炼成的:精妙SQL语句介绍.. 
 普通文章 MYSQL用户root密码为弱口令的攻击.. 
 普通文章 MySQL中修改密码及访问限制设置详.. 
 普通文章 SQL 语法参考 
 推荐文章 MySQL数据库函数详解(1) 
 推荐文章 Mysql的常用命令 
 普通文章 MySQL丢了root密码怎么办 
最新文章 最新推荐文章 热门文章
 普通文章 简历封面 
 普通文章 简历封皮(二) 
 推荐文章 用好Windows共享 确保安全 
 推荐文章 多点出发:消除局域网遗留共享痕迹.. 
 普通文章 只需三步!闪盘立刻变成启动盘 
 普通文章 战无不胜 一目了然看穿局域网 
 普通文章 Win 2000/XP在局域网内批量升级 
 普通文章 黑客经常更改的系统配置文件及注册.. 
 推荐文章 用好Windows共享 确保安全 
 推荐文章 多点出发:消除局域网遗留共享痕迹.. 
 推荐文章 Ghost二十个鲜为人知的实用参数 
 推荐文章 ASP.NET程序中常用的三十三种代码.. 
 推荐文章 黑客利用Ms05002溢出找“肉鸡” 
 推荐文章 C# 3.0语言详解之基本的语言增强 .. 
 推荐文章 Ghost所有运行错误代码完全大揭秘.. 
 推荐文章 利用Java Swing 实现游戏开发 
 推荐文章 秘籍:QQ头像任意换 
 普通文章 提升QQ等级 QQ挂机升级外挂  
 普通文章 QQ100个经典个性签名!可爱经典贴图.. 
 推荐文章 BIOS设置图解教程(多图) 
 普通文章 惊现腾讯QQ刷等级漏洞 
 普通文章 求职简历封皮  
 普通文章 突破在线观看电影 
 普通文章 GIF动画图片制作教程 
点击查看更多评论
笔名:
评论:
[评论将在5分钟内被审核,请耐心等待]
【注】 发表评论必需遵守以下条例:
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
  • 本站大部分为网络转载,如有版权问题,请通知我们,我们立即更正!

设置首页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
Copyright ©2003-2005 xker.com All rights reserved. 网站合作、广告联系QQ:12231446
小新技术网  冀ICP备05002857号