php-doc-en/reference/mysqli/functions/mysqli-field-count.xml
Nuno Lopes ccba0320cb fix : typo in the examples
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@160642 c90b9560-bf6c-de11-be94-00142212c4b1
2004-06-06 09:19:02 +00:00

126 lines
3.4 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.9 $ -->
<refentry id="function.mysqli-field-count">
<refnamediv>
<refname>mysqli_field_count</refname>
<refname>mysqli->field_count</refname>
<refpurpose>Returns the number of columns for the most recent query</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>Procedural style:</para>
<methodsynopsis>
<type>int</type><methodname>mysqli_field_count</methodname>
<methodparam><type>object</type><parameter>link</parameter></methodparam>
</methodsynopsis>
<para>Object oriented style (method):</para>
<classsynopsis>
<ooclass><classname>mysql</classname></ooclass>
<methodsynopsis>
<type>int</type>
<methodname>field_count</methodname>
<void />
</methodsynopsis>
</classsynopsis>
<para>
Returns the number of columns for the most recent query on the connection
represented by the <parameter>link</parameter> parameter. This function
can be useful when using the <function>mysqli_store_result</function>
function to determine if the query should have produced a non-empty result
set or not without knowing the nature of the query.
</para>
</refsect1>
<refsect1>
<title>Return values</title>
<para>An integer representing the number of fields in a result set</para>
</refsect1>
<refsect1>
<title>Example</title>
<para>
<example>
<title>Object oriented style</title>
<programlisting role='php'>
<![CDATA[
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
$mysqli->query( "DROP TABLE IF EXISTS friends");
$mysqli->query( "CREATE TABLE friends (id int, name varchar(20))");
$mysqli->query( "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')");
$mysqli->real_query($HTTP_POST_VARS['query']);
if (mysqli_field_count($link)) {
/* this was a select/show or describe query */
$result = $mysqli->store_result();
/* process resultset */
$row = $result->fetch_row();
/* free resultset */
$result->close();
}
/* close connection */
$mysqli->close();
?>
]]>
</programlisting>
</example>
<example>
<title>Procedural style</title>
<programlisting role='php'>
<![CDATA[
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "test");
mysqli_query($link, "DROP TABLE IF EXISTS friends");
mysqli_query($link, "CREATE TABLE friends (id int, name varchar(20))");
mysqli_query($link, "INSERT INTO friends VALUES (1,'Hartmut'), (2, 'Ulf')");
mysqli_real_query($link, $HTTP_POST_VARS['query']);
if (mysqli_field_count($link)) {
/* this was a select/show or describe query */
$result = mysqli_store_result($link);
/* process resultset */
$row = mysqli_fetch_row($result);
/* free resultset */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->