php-doc-en/reference/mysqli/functions/mysqli-warning-count.xml
Jakub Vrana 008a657c1a Change "object" to specific objects
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@172550 c90b9560-bf6c-de11-be94-00142212c4b1
2004-11-12 14:01:04 +00:00

147 lines
3.9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
<refentry id="function.mysqli-warning-count">
<refnamediv>
<refname>mysqli_warning_count</refname>
<refname>mysqli->warning_count</refname>
<refpurpose>Returns the number of warnings from the last query for the given link</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>Procedural style:</para>
<methodsynopsis>
<type>int</type><methodname>mysqli_warning_count</methodname>
<methodparam><type>mysqli</type><parameter>link</parameter></methodparam>
</methodsynopsis>
<para>Object oriented style (property):</para>
<classsynopsis>
<ooclass><classname>mysqli</classname></ooclass>
<fieldsynopsis><type>int</type><varname>warning_count</varname></fieldsynopsis>
</classsynopsis>
<para>
<function>mysqli_warning_count</function> returns the number of warnings
from the last query in the connection represented by the
<parameter>link</parameter> parameter.
</para>
<note>
<para>
For retrieving warning messages you can use the SQL command
<literal>SHOW WARNINGS [limit row_count]</literal>.
</para>
</note>
</refsect1>
<refsect1>
&reftitle.returnvalues;
<para>
Number of warnings or zero if there are no warnings.
</para>
</refsect1>
<refsect1>
&reftitle.seealso;
<para>
<function>mysqli_errno</function>,
<function>mysqli_error</function>&listendand;
<function>mysqli_sqlstate</function>.
</para>
</refsect1>
<refsect1>
&reftitle.examples;
<example>
<title>Object oriented style</title>
<programlisting role="php">
<![CDATA[
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$mysqli->query("CREATE TABLE myCity LIKE City");
/* a remarkable city in Wales */
$query = "INSERT INTO myCity (CountryCode, Name) VALUES('GBR',
'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')";
$mysqli->query($query);
if ($mysqli->warning_count) {
if ($result = $mysqli->query("SHOW WARNINGS")) {
$row = $result->fetch_row();
printf("%s (%d): %s\n", $row[0], $row[1], $row[2]);
$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", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
mysqli_query($link, "CREATE TABLE myCity LIKE City");
/* a remarkable long city name in Wales */
$query = "INSERT INTO myCity (CountryCode, Name) VALUES('GBR',
'Llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch')";
mysqli_query($link, $query);
if (mysqli_warning_count($link)) {
if ($result = mysqli_query($link, "SHOW WARNINGS")) {
$row = mysqli_fetch_row($result);
printf("%s (%d): %s\n", $row[0], $row[1], $row[2]);
mysqli_free_result($result);
}
}
/* close connection */
mysqli_close($link);
?>
]]>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
Warning (1264): Data truncated for column 'Name' at row 1
]]>
</screen>
</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
-->