Home  >  Article  >  Backend Development  >  快速掌握PHP获取字段数据类型技巧_PHP教程

快速掌握PHP获取字段数据类型技巧_PHP教程

WBOY
WBOYOriginal
2016-07-15 13:35:091046browse

对于一个初学者来说,他们在学习的过程中肯定要学到灵活的运用各种

mysql_field_type()函数可获得字段的数据类型,该函数的语法格式如下。

string mysql_field_type ( resource $result, int $field_offset )

mysql_field_type()函数类似于函数mysql_field_name(),不过mysql_field_type()函数返回的是字段的数据类型。它的参数的描述如下。

l result:mysql_query()函数执行后返回的结果集。

l field_offset:字段的偏移量,起始值为零。

使用mysql_field_type()函数的示例代码如下:

代码23-12 光盘codes第23章23.3mysql_field_type.php

  1.  ?php  
  2. $connection=mysql_connect("localhost",
    "root","root") or die("连接服务器失败");  
  3. mysql_select_db("sunyang",$connection) 
    or die("选择数据库失败");  
  4. $query="select * from employee";  
  5. $result=mysql_query($query) or die
    ("查询数据失败");   
  6. //执行查询  
  7. echo mysql_field_type($result,0);   
  8. //第一个字段的数据类型  
  9. echo " br>";  
  10. echo mysql_field_type($result,1);   
  11. //第二个字段的数据类型  
  12. echo " br>";  
  13. echo mysql_field_type($result,2);   
  14. //第三个字段的数据类型  
  15. mysql_free_result($result);  
  16. mysql_close();  
  17. ?>  

上面代码执行后将把表employee中的前3个字段的数据类型输出。


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445931.htmlTechArticle对于一个初学者来说,他们在学习的过程中肯定要学到灵活的运用各种 mysql_field_type()函数可获得字段的数据类型,该函数的语法格式如下。...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn