Source of: /manual/en/function.sqlite-fetch-single.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.sqlite.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'function.sqlite-fetch-single.php',
1 => 'sqlite_fetch_single',
),
'up' =>
array (
0 => 'ref.sqlite.php',
1 => 'SQLite Functions',
),
'prev' =>
array (
0 => 'function.sqlite-fetch-object.php',
1 => 'sqlite_fetch_object',
),
'next' =>
array (
0 => 'function.sqlite-fetch-string.php',
1 => 'sqlite_fetch_string',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div id="function.sqlite-fetch-single" class="refentry">
<div class="refnamediv">
<h1 class="refname">sqlite_fetch_single</h1>
<h1 class="refname">SQLiteResult->fetchSingle</h1>
<h1 class="refname">SQLiteUnbuffered->fetchSingle</h1>
<p class="verinfo">(PHP 5, PECL sqlite >= 1.0.1)</p><p class="refpurpose"><span class="refname">sqlite_fetch_single</span> -- <span class="refname">SQLiteResult->fetchSingle</span> -- <span class="refname">SQLiteUnbuffered->fetchSingle</span> — <span class="dc-title">Fetches the first column of a result set as a string</span></p>
</div>
<a name="function.sqlite-fetch-single.description"></a><div class="refsect1 description">
<h3 class="title">Description</h3>
<div class="methodsynopsis dc-description">
<span class="type">string</span> <span class="methodname"><b>sqlite_fetch_single</b></span>
( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$result</tt></span>
[, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$decode_binary</tt><span class="initializer"> = true</span></span>
] )</div>
<p class="para rdfs-comment">Object oriented style (method):</p>
<div class="classsynopsis">
<div class="ooclass"><b class="classname">SQLiteResult</b></div>
<div class="methodsynopsis dc-description">
<span class="type">string</span> <span class="methodname"><b>fetchSingle</b></span>
([ <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$decode_binary</tt><span class="initializer"> = true</span></span>
] )</div>
</div>
<div class="classsynopsis">
<div class="ooclass"><b class="classname">SQLiteUnbuffered</b></div>
<div class="methodsynopsis dc-description">
<span class="type">string</span> <span class="methodname"><b>fetchSingle</b></span>
([ <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$decode_binary</tt><span class="initializer"> = true</span></span>
] )</div>
</div>
<p class="para">
<b>sqlite_fetch_single()</b> is identical to
<a href="function.sqlite-fetch-array.php" class="function">sqlite_fetch_array()</a> except that it returns the value
of the first column of the rowset.
</p>
<p class="para">
This is the most optimal way to retrieve data when you are only
interested in the values from a single column of data.
</p>
</div>
<a name="function.sqlite-fetch-single.parameters"></a><div class="refsect1 parameters">
<h3 class="title">Parameters</h3>
<p class="para">
</p><dl>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">result</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">
The SQLite result resource. This parameter is not required when using
the object-oriented method.
</p>
</dd>
<dt class="varlistentry">
<span class="term"><i><tt class="parameter">decode_binary</tt></i>
</span>
</dt><dd class="listitem">
<p class="para">When the <i><tt class="parameter">decode_binary</tt></i>
parameter is set to <b><tt class="constant">TRUE</tt></b> (the default), PHP will decode the binary encoding
it applied to the data if it was encoded using the
<a href="function.sqlite-escape-string.php" class="function">sqlite_escape_string()</a>. You should normally leave this
value at its default, unless you are interoperating with databases created by
other sqlite capable applications.</p>
</dd>
</dl>
<p>
</p>
</div>
<a name="function.sqlite-fetch-single.returnvalues"></a><div class="refsect1 returnvalues">
<h3 class="title">Return Values</h3>
<p class="para">
Returns the first column value, as a string.
</p>
</div>
<a name="function.sqlite-fetch-single.examples"></a><div class="refsect1 examples">
<h3 class="title">Examples</h3>
<p class="para">
</p><div class="example">
<p><b>Example #1 A <b>sqlite_fetch_single()</b> example</b></p>
<div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">$dbhandle </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'mysqlitedb'</span><span style="color: #007700">, </span><span style="color: #0000BB">0666</span><span style="color: #007700">, </span><span style="color: #0000BB">$sqliteerror</span><span style="color: #007700">)) {<br /><br /> </span><span style="color: #0000BB">$sql </span><span style="color: #007700">= </span><span style="color: #DD0000">"SELECT id FROM sometable WHERE id = 42"</span><span style="color: #007700">;<br /> </span><span style="color: #0000BB">$res </span><span style="color: #007700">= </span><span style="color: #0000BB">sqlite_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">, </span><span style="color: #0000BB">$sql</span><span style="color: #007700">);<br /><br /> if (</span><span style="color: #0000BB">sqlite_num_rows</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">) > </span><span style="color: #0000BB">0</span><span style="color: #007700">) {<br /> echo </span><span style="color: #0000BB">sqlite_fetch_single</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">); </span><span style="color: #FF8000">// 42<br /> </span><span style="color: #007700">}<br /> <br /> </span><span style="color: #0000BB">sqlite_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$dbhandle</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?></span>
</span>
</code></div>
</div>
</div><p>
</p>
</div>
<a name="function.sqlite-fetch-single.seealso"></a><div class="refsect1 seealso">
<h3 class="title">See Also</h3>
<p class="para">
</p><ul class="simplelist">
<li class="member"><a href="function.sqlite-fetch-array.php" class="function" rel="rdfs-seeAlso">sqlite_fetch_array()</a> - Fetches the next row from a result set as an array</li>
</ul><p>
</p>
</div>
</div><?php manual_footer(); ?>