<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >sqlite_query</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="PHP 手册" HREF="index.html"><LINK REL="UP" TITLE="SQLite Functions" HREF="ref.sqlite.html"><LINK REL="PREVIOUS" TITLE="sqlite_prev" HREF="function.sqlite-prev.html"><LINK REL="NEXT" TITLE="sqlite_rewind" HREF="function.sqlite-rewind.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP 手册</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.sqlite-prev.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.sqlite-rewind.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.sqlite-query" ></A >sqlite_query</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN217754" ></A ><P > (PHP 5)</P >sqlite_query<P > (no version information, might be only in CVS)</P >SQLiteDatabase->query -- Executes a query against a given database and returns a result handle</DIV ><DIV CLASS="refsect1" ><A NAME="AEN217758" ></A ><H2 >说明</H2 >resource <B CLASS="methodname" >sqlite_query</B > ( resource dbhandle, string query [, int result_type [, string &error_msg]] )<BR ></BR >resource <B CLASS="methodname" >sqlite_query</B > ( string query, resource dbhandle [, int result_type [, string &error_msg]] )<BR ></BR ><P >Object oriented style (method):</P >class <B CLASS="classname" >SQLiteDatabase</B > { <BR ></BR >SQLiteResult <B CLASS="methodname" >query</B > ( string query [, int result_type [, string &error_msg]] )<BR ></BR >}<P > Executes an SQL statement given by the <CODE CLASS="parameter" >query</CODE > against a given database handle. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN217808" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >dbhandle</CODE ></DT ><DD ><P > The SQLite Database resource; returned from <A HREF="function.sqlite-open.html" ><B CLASS="function" >sqlite_open()</B ></A > when used procedurally. This parameter is not required when using the object-oriented method. </P ></DD ><DT ><CODE CLASS="parameter" >query</CODE ></DT ><DD ><P > The query to be executed. </P ></DD ><DT ><CODE CLASS="parameter" >result_type</CODE ></DT ><DD ><P >可选的 <CODE CLASS="parameter" >result_type</CODE > 参数接受一个常量并决定返回的数组如何索引。用 <TT CLASS="constant" ><B >SQLITE_ASSOC</B ></TT > 只会返回关联索引(有名称字段)而 <TT CLASS="constant" ><B >SQLITE_NUM</B ></TT > 只会返回数字索引(有序字段数)。<TT CLASS="constant" ><B >SQLITE_BOTH</B ></TT > 会同时返回关联和数字索引。 <TT CLASS="constant" ><B >SQLITE_BOTH</B ></TT > 是本函数的默认值。</P ></DD ><DT ><CODE CLASS="parameter" >error_msg</CODE ></DT ><DD ><P > 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" ><B CLASS="function" >sqlite_last_error()</B ></A > function. </P ></DD ></DL ></DIV > </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B >为兼容其它数据库(例如 MySQL),支持另两种替代的语法。推荐用第一种,<CODE CLASS="parameter" >dbhandle</CODE > 参数作为函数的第一个参数。</P ></BLOCKQUOTE ></DIV ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN217842" ></A ><H2 >返回值</H2 ><P > This function will return a result handle or <TT CLASS="constant" ><B >FALSE</B ></TT > 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" ><B CLASS="function" >sqlite_fetch_array()</B ></A > and <A HREF="function.sqlite-seek.html" ><B CLASS="function" >sqlite_seek()</B ></A >. </P ><P > Regardless of the query type, this function will return <TT CLASS="constant" ><B >FALSE</B ></TT > if the query failed. </P ><P > <B CLASS="function" >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" ><B CLASS="function" >sqlite_unbuffered_query()</B ></A > instead. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN217853" ></A ><H2 >更新日志</H2 ><P > <DIV CLASS="informaltable" ><P ></P ><A NAME="AEN217856" ></A ><TABLE BORDER="1" CLASS="CALSTABLE" ><COL><COL><THEAD ><TR ><TH >版本</TH ><TH >说明</TH ></TR ></THEAD ><TBODY ><TR ><TD >5.1.0</TD ><TD > Added the <CODE CLASS="parameter" >error_msg</CODE > parameter </TD ></TR ></TBODY ></TABLE ><P ></P ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN217867" ></A ><H2 >注释</H2 ><DIV CLASS="warning" ><P ></P ><TABLE CLASS="warning" BORDER="1" WIDTH="100%" ><TR ><TD ALIGN="CENTER" ><B >警告</B ></TD ></TR ><TR ><TD ALIGN="LEFT" ><P > SQLite <SPAN CLASS="emphasis" ><I CLASS="emphasis" >will</I ></SPAN > 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" ><B CLASS="function" >sqlite_exec()</B ></A > will always execute multiple SQL statements. </P ><P > When executing multiple queries, the return value of this function will be <TT CLASS="constant" ><B >FALSE</B ></TT > if there was an error, but undefined otherwise (it might be <TT CLASS="constant" ><B >TRUE</B ></TT > for success or it might return a result handle). </P ></TD ></TR ></TABLE ></DIV ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN217876" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.sqlite-unbuffered-query.html" ><B CLASS="function" >sqlite_unbuffered_query()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.sqlite-array-query.html" ><B CLASS="function" >sqlite_array_query()</B ></A ></TD ></TR ></TBODY ></TABLE ><P ></P > </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.sqlite-prev.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >起始页</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.sqlite-rewind.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >sqlite_prev</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.sqlite.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >sqlite_rewind</TD ></TR ></TABLE ></DIV ></BODY ></HTML >