快速掌握PHP擷取欄位資料類型技巧_PHP教程

來源:互聯網
上載者:User
對於一個初學者來說,他們在學習的過程中肯定要學到靈活的運用各種

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個欄位的資料類型輸出。


http://www.bkjia.com/PHPjc/445931.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445931.htmlTechArticle對於一個初學者來說,他們在學習的過程中肯定要學到靈活的運用各種 mysql_field_type()函數可獲得欄位的資料類型,該函數的文法格式如下。...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.