function.sqlite-query.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 231 行
HTML
231 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Executes a query against a given database and returns a result handle</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-prev.html">sqlite_prev</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-rewind.html">sqlite_rewind</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-query" class="refentry"> <div class="refnamediv"> <h1 class="refname">sqlite_query</h1> <h1 class="refname">SQLiteDatabase->query</h1> <p class="verinfo">(PHP 5, PECL sqlite:1.0-1.0.3)</p><p class="refpurpose"><span class="refname">sqlite_query</span> -- <span class="refname">SQLiteDatabase->query</span> — <span class="dc-title">Executes a query against a given database and returns a result handle</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><b><b>sqlite_query</b></b></span> ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$dbhandle</tt></span> , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$result_type</tt></span> [, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&$error_msg</tt></span> ]] )</div> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><b><b>sqlite_query</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span> , <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$dbhandle</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$result_type</tt></span> [, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&$error_msg</tt></span> ]] )</div> <p class="para rdfs-comment">Object oriented style (method):</p> <div class="classsynopsis"> <div class="ooclass"><b class="classname">SQLiteDatabase</b></div> <div class="methodsynopsis dc-description"> <span class="type">SQLiteResult</span> <span class="methodname"><b><b>query</b></b></span> ( <span class="methodparam"><span class="type">string</span> <tt class="parameter">$query</tt></span> [, <span class="methodparam"><span class="type">int</span> <tt class="parameter">$result_type</tt></span> [, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&$error_msg</tt></span> ]] )</div> </div> <p class="para"> Executes an SQL statement given by the <i><tt class="parameter">query</tt></i> against a given database handle. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">dbhandle</tt></i></span> <dd> <p class="para"> The SQLite Database resource; returned from <a href="function.sqlite-open.html" class="function">sqlite_open()</a> when used procedurally. This parameter is not required when using the object-oriented method. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">query</tt></i></span> <dd> <p class="para"> The query to be executed. </p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">result_type</tt></i></span> <dd> <p class="para">The optional <i><tt class="parameter">result_type</tt></i>parameter accepts a constant and determines how the returned array will beindexed. Using <b><tt>SQLITE_ASSOC</tt></b> will return only associativeindices (named fields) while <b><tt>SQLITE_NUM</tt></b> will returnonly numerical indices (ordinal field numbers). <b><tt>SQLITE_BOTH</tt></b>will return both associative and numerical indices.<b><tt>SQLITE_BOTH</tt></b> is the default for this function.</p> </dd> </dt> <dt> <span class="term"><i><tt class="parameter">error_msg</tt></i></span> <dd> <p class="para"> The specified variable will be filled if an error occurs. This is specially important because SQL syntax errors can't be fetched using the <a href="function.sqlite-last-error.html" class="function">sqlite_last_error()</a> function. </p> </dd> </dt> </dl> </p> <blockquote><p><b class="note">Note</b>: <span class="simpara">Two alternative syntaxes aresupported for compatibility with other database extensions (such as MySQL).The preferred form is the first, where the <i><tt class="parameter">dbhandle</tt></i>parameter is the first parameter to the function.</span></p></blockquote> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> This function will return a result handle or <b><tt>FALSE</tt></b> on failure. For queries that return rows, the result handle can then be used with functions such as <a href="function.sqlite-fetch-array.html" class="function">sqlite_fetch_array()</a> and <a href="function.sqlite-seek.html" class="function">sqlite_seek()</a>. </p> <p class="para"> Regardless of the query type, this function will return <b><tt>FALSE</tt></b> if the query failed. </p> <p class="para"> <b>sqlite_query()</b> returns a buffered, seekable result handle. This is useful for reasonably small queries where you need to be able to randomly access the rows. Buffered result handles will allocate memory to hold the entire result and will not return until it has been fetched. If you only need sequential access to the data, it is recommended that you use the much higher performance <a href="function.sqlite-unbuffered-query.html" class="function">sqlite_unbuffered_query()</a> instead. </p> </div><div class="refsect1 changelog"> <h3 class="title">ChangeLog</h3> <p class="para"> <table class="informaltable"> <colgroup> <thead valign="middle"> <tr valign="middle"> <th colspan="1">Version</th> <th colspan="1">Description</th> </tr> </thead> <tbody valign="middle" class="tbody"> <tr valign="middle"> <td colspan="1" rowspan="1" align="left">5.1.0</td> <td colspan="1" rowspan="1" align="left"> Added the <i><tt class="parameter">error_msg</tt></i> parameter </td> </tr> </tbody> </colgroup> </table> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <div class="warning"><b class="warning">Warning</b> <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. However, this works only when the result of the function is not used - if it is used, only the first SQL statement would be executed. Function <a href="function.sqlite-exec.html" class="function">sqlite_exec()</a> will always execute multiple SQL statements. </p> <p class="simpara"> When executing multiple queries, the return value of this function will be <b><tt>FALSE</tt></b> if there was an error, but undefined otherwise (it might be <b><tt>TRUE</tt></b> for success or it might return a result handle). </p> </div> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.sqlite-unbuffered-query.html" class="function" rel="rdfs-seeAlso">sqlite_unbuffered_query()</a></li> <li class="member"><a href="function.sqlite-array-query.html" class="function" rel="rdfs-seeAlso">sqlite_array_query()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.sqlite-prev.html">sqlite_prev</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.sqlite-rewind.html">sqlite_rewind</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>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?