Explain the techniques of obtaining field attributes in PHP_PHP tutorial

WBOY
Release: 2016-07-15 13:35:15
Original
816 people have browsed it

During WEB development, you will always encounter database-related operations. As a beginner, this is something you must master. Let’s analyze it in detail. In addition to the field name, data type, and length, the

field also has some other attributes, such as whether it is a primary key, whether it is a foreign key, and whether it is allowed to be Waiting. PHP can obtain field attributes through the mysql_field_flags() function. The syntax format of this function is as follows:

string mysql_field_flags ( resource $result, int $field_offset )

Parameter descriptions involved in the above syntax As follows:

l result: the result set returned after the mysql_query() function is executed.

l field_offset: The offset of the field, the starting value is zero.

The sample code for PHP to obtain field attributes using the mysql_field_flags() function is as follows:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><</span><span> ?php  </span></span></li><li><span>$</span><span class="attribute">connection</span><span>=</span><span class="attribute-value">mysql_connect</span><span>("localhost",<br />"root","root") or die("连接服务器失败");  </span></li><li class="alt"><span>mysql_select_db("sunyang",$connection) <br />or die("选择数据库失败");  </span></li><li><span>$</span><span class="attribute">query</span><span>=</span><span class="attribute-value">"select * from employee"</span><span>;  </span></li><li class="alt"><span>$</span><span class="attribute">result</span><span>=</span><span class="attribute-value">mysql_query</span><span>($query) or die<br />("查询数据失败"); //执行查询  </span></li><li><span>echo mysql_field_flags($result, 0); <br />//第一个字段的属性  </span></li><li class="alt"><span>echo "</span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span>";  </span></span></li>
<li><span>echo mysql_field_flags($result, 1); <br>//第二个字段的属性  </span></li>
<li class="alt">
<span>echo "</span><span class="tag"><</span><span class="tag-name">br</span><span class="tag">></span><span>";  </span>
</li>
<li><span>echo mysql_field_flags($result, 2); <br>//第三个字段的属性  </span></li>
<li class="alt"><span>mysql_free_result($result);  </span></li>
<li><span>mysql_close();  </span></li>
<li class="alt">
<span class="tag">?></span><span>  </span>
</li>
</ol>
Copy after login

The above is the PHP acquisition we share with you Tips related to field properties.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445928.htmlTechArticleDuring WEB development, you will always encounter database-related operations. As a beginner, this is something you must master. Let’s analyze it in detail. In addition to field names, fields...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!