<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.9 $ --> <refentry id="function.mysqli-execute"> <refnamediv> <refname>mysqli_execute</refname> <refname>stmt->execute</refname> <refpurpose>Executes a prepared Query</refpurpose> </refnamediv> <refsect1> <title>Description</title> <para>Procedural style:</para> <methodsynopsis> <type>bool</type><methodname>mysqli_execute</methodname> <methodparam><type>object</type><parameter>stmt</parameter></methodparam> </methodsynopsis> <para>Object oriented style (method):</para> <classsynopsis> <ooclass><classname>mysql</classname></ooclass> <methodsynopsis> <type>bool</type> <methodname>execute</methodname> <methodparam><type>void</type><parameter></parameter></methodparam> </methodsynopsis> </classsynopsis> <para> The <function>mysqli_execute</function> function executes a query that has been previously prepared using the <function>mysqli_prepare</function> function represented by the <parameter>stmt</parameter> object. When executed any parameter markers which exist will automatically be replaced with the appropiate data. </para> <para> If the statement is UPDATE, DELETE, or INSERT, the total number of affected rows can be determined by using the <function>mysqli_stmt_affected_rows</function> function. Likewise, if the query yields a result set the <function>mysqli_fetch</function> function is used. </para> <note> <para> When using <function>mysqli_execute</function>, the <function>mysqli_fetch</function> function must be used to fetch the data prior to preforming any additional queries. </para> </note> </refsect1> <refsect1> <title>Return values</title> <para>&return.success;</para> </refsect1> <refsect1> <title>See also</title> <para> <function>mysqli_prepare</function> <function>mysqli_bind_param</function>. </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))"); /* Prepare an insert statement */ $query = "INSERT INTO friends VALUES(?, ?)"; $stmt = $mysqli->prepare($query); $stmt->bind_param("is", $val1, $val2); $val1 = 1; $val2 = 'Miller'; /* Execute the statement */ $stmt->execute(); $val1 = 2; $val2 = 'Wagner'; /* Execute the statement */ $stmt->execute(); $stmt->close(); /* Return the affected rows for the statement */ if ($result = $mysqli->query("SELECT id,name FROM friends")) { while ($row = $result->fetch_row()) { printf("ID: %s Name: %s\n", $row[0], $row[1]); } $result->close(); } $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))"); /* Prepare an insert statement */ $query = "INSERT INTO friends VALUES(?, ?)"; $stmt = mysqli_prepare($link, $query); mysqli_bind_param($stmt, "is", $val1, $val2); $val1 = 1; $val2 = 'Miller'; /* Execute the statement */ mysqli_execute($stmt); $val1 = 2; $val2 = 'Wagner'; /* Execute the statement */ mysqli_execute($stmt); mysqli_stmt_close($stmt); /* Return the affected rows for the statement */ if ($result = mysqli_query($link, "SELECT id,name FROM friends")) { while ($row = mysqli_fetch_row($result)) { printf("ID: %s Name: %s\n", $row[0], $row[1]); } mysqli_free_result($result); } 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 -->