php-doc-en/reference/mysqli/functions/mysqli-stmt-error.xml

149 lines
3.7 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.8 $ -->
<refentry id="function.mysqli-stmt-error">
<refnamediv>
<refname>mysqli_stmt_error</refname>
<refname>mysqli_stmt->error</refname>
<refpurpose>Returns a string description for last statement error</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>Procedural style:</para>
<methodsynopsis>
<type>string</type><methodname>mysqli_stmt_error</methodname>
<methodparam><type>mysqli_stmt</type><parameter>stmt</parameter></methodparam>
</methodsynopsis>
<para>Object oriented style (property):</para>
<classsynopsis>
<ooclass><classname>mysqli_stmt</classname></ooclass>
<fieldsynopsis><type>string</type><varname>error</varname></fieldsynopsis>
</classsynopsis>
<para>
For the statement specified by <literal>stmt</literal>, <function>mysqli_stmt_error</function>
returns a containing the error message for the most recently invoked statement function that
can succeed or fail.
</para>
</refsect1>
<refsect1>
&reftitle.returnvalues;
<para>
A string that describes the error. An empty string if no error occurred.
</para>
</refsect1>
<refsect1>
&reftitle.seealso;
<para>
<function>mysqli_stmt_errno</function>&listendand;
<function>mysqli_stmt_sqlstate</function>.
</para>
</refsect1>
<refsect1>
&reftitle.examples;
<example>
<title>Object oriented style</title>
<programlisting role="php">
<![CDATA[
<?php
/* Open a connection */
$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 myCountry LIKE Country");
$mysqli->query("INSERT INTO myCountry SELECT * FROM Country");
$query = "SELECT Name, Code FROM myCountry ORDER BY Name";
if ($stmt = $mysqli->prepare($query)) {
/* drop table */
$mysqli->query("DROP TABLE myCountry");
/* execute query */
$stmt->execute();
printf("Error: %s.\n", $stmt->error);
/* close statement */
$stmt->close();
}
/* close connection */
$mysqli->close();
?>
]]>
</programlisting>
</example>
<example>
<title>Procedural style</title>
<programlisting role="php">
<![CDATA[
<?php
/* Open a connection */
$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 myCountry LIKE Country");
mysqli_query($link, "INSERT INTO myCountry SELECT * FROM Country");
$query = "SELECT Name, Code FROM myCountry ORDER BY Name";
if ($stmt = mysqli_prepare($link, $query)) {
/* drop table */
mysqli_query($link, "DROP TABLE myCountry");
/* execute query */
mysqli_stmt_execute($stmt);
printf("Error: %s.\n", mysqli_stmt_error($stmt));
/* close statement */
mysqli_stmt_close($stmt);
}
/* close connection */
mysqli_close($link);
?>
]]>
</programlisting>
</example>
&example.outputs;
<screen>
<![CDATA[
Error: Table 'world.myCountry' doesn't exist.
]]>
</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
-->