选择显示字体大小

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>
");
}
?>


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons