Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 5858

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Executes a result-less query against a given database</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-escape-string.html">sqlite_escape_string</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-factory.html">sqlite_factory</a></div>
 <div class="up"><a href="ref.sqlite.html">SQLite Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.sqlite-exec" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sqlite_exec</h1>
  <h1 class="refname">SQLiteDatabase::exec</h1>
  <p class="verinfo">(PHP 5 &lt; 5.4.0, PECL sqlite &gt;= 1.0.3)</p><p class="refpurpose"><span class="refname">sqlite_exec</span> -- <span class="refname">SQLiteDatabase::exec</span> &mdash; <span class="dc-title">Executes a result-less query against a given database</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sqlite-exec-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>sqlite_exec</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$dbhandle</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$error_msg</code></span>
  ] )</div>

  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>sqlite_exec</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
   , <span class="methodparam"><span class="type">resource</span> <code class="parameter">$dbhandle</code></span>
   )</div>

  <p class="para rdfs-comment">Object oriented style (method):</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">bool</span> <span class="methodname"><strong>SQLiteDatabase::queryExec</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$query</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$error_msg</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Executes an SQL statement given by the <em><code class="parameter">query</code></em> against
   a given database handle (specified by the <em><code class="parameter">dbhandle</code></em> 
   parameter).
  </p>
  <div class="warning"><strong class="warning">Warning</strong>
   <p class="simpara">
    SQLite <em class="emphasis">will</em> execute multiple queries separated by
    semicolons, so you can use it to execute a batch of SQL that you have
    loaded from a file or have embedded in a script.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sqlite-exec-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">dbhandle</code></em></span>
     <dd>

      <p class="para">
       The SQLite Database resource; returned from
        <span class="function"><a href="function.sqlite-open.html" class="function">sqlite_open()</a></span> when used procedurally. This parameter
       is not required when using the object-oriented method.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">query</code></em></span>
     <dd>

      <p class="para">
       The query to be executed.
      </p>
      <p class="para">
       Data inside the query should be <a href="function.sqlite-escape-string.html" class="link">properly escaped</a>.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">error_msg</code></em></span>
     <dd>

      <p class="para">
       The specified variable will be filled if an error occurs. This is
       specially important because SQL syntax errors can&#039;t be fetched using
       the  <span class="function"><a href="function.sqlite-last-error.html" class="function">sqlite_last_error()</a></span> function.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">Two alternative syntaxes are
supported for compatibility with other database extensions (such as MySQL).
The preferred form is the first, where the <em><code class="parameter">dbhandle</code></em>
parameter is the first parameter to the function.</span></p></blockquote>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sqlite-exec-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   This function will return a boolean result; <strong><code>TRUE</code></strong> for success or <strong><code>FALSE</code></strong> for failure.
   If you need to run a query that returns rows, see  <span class="function"><a href="function.sqlite-query.html" class="function">sqlite_query()</a></span>.
  </p>
  <p class="para">The column names returned by
<strong><code>SQLITE_ASSOC</code></strong> and <strong><code>SQLITE_BOTH</code></strong> will be
case-folded according to the value of the
<a href="sqlite.configuration.html#ini.sqlite.assoc-case" class="link">sqlite.assoc_case</a> configuration
option.</p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.sqlite-exec-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        Added the <em><code class="parameter">error_msg</code></em> parameter
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>



 <div class="refsect1 examples" id="refsect1-function.sqlite-exec-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-2140">
    <p><strong>Example #1 Procedural example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dbhandle&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlite_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlite_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UPDATE&nbsp;users&nbsp;SET&nbsp;email='jDoe@example.com'&nbsp;WHERE&nbsp;username='jDoe'"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$query</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #DD0000">"Error&nbsp;in&nbsp;query:&nbsp;'</span><span style="color: #0000BB">$error</span><span style="color: #DD0000">'"</span><span style="color: #007700">);<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Number&nbsp;of&nbsp;rows&nbsp;modified:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">sqlite_changes</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2141">
    <p><strong>Example #2 Object-oriented example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$dbhandle&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">SQLiteDatabase</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$query&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">queryExec</span><span style="color: #007700">(</span><span style="color: #DD0000">"UPDATE&nbsp;users&nbsp;SET&nbsp;email='jDoe@example.com'&nbsp;WHERE&nbsp;username='jDoe'"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$error</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$query</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;exit(</span><span style="color: #DD0000">"Error&nbsp;in&nbsp;query:&nbsp;'</span><span style="color: #0000BB">$error</span><span style="color: #DD0000">'"</span><span style="color: #007700">);<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Number&nbsp;of&nbsp;rows&nbsp;modified:&nbsp;'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">changes</span><span style="color: #007700">();<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.sqlite-exec-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.sqlite-query.html" class="function" rel="rdfs-seeAlso">sqlite_query()</a> - Executes a query against a given database and returns a result handle</span></li>
    <li class="member"> <span class="function"><a href="function.sqlite-unbuffered-query.html" class="function" rel="rdfs-seeAlso">sqlite_unbuffered_query()</a> - Execute a query that does not prefetch and buffer all data</span></li>
    <li class="member"> <span class="function"><a href="function.sqlite-array-query.html" class="function" rel="rdfs-seeAlso">sqlite_array_query()</a> - Execute a query against a given database and returns an array</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-escape-string.html">sqlite_escape_string</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-factory.html">sqlite_factory</a></div>
 <div class="up"><a href="ref.sqlite.html">SQLite Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>