<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >fbsql_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="FrontBase Functions" HREF="ref.fbsql.html"><LINK REL="PREVIOUS" TITLE="fbsql_pconnect" HREF="function.fbsql-pconnect.html"><LINK REL="NEXT" TITLE="fbsql_read_blob" HREF="function.fbsql-read-blob.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.fbsql-pconnect.html" ACCESSKEY="P" >上一页</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.fbsql-read-blob.html" ACCESSKEY="N" >下一页</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.fbsql-query" ></A >fbsql_query</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN60265" ></A ><P > (PHP 4 >= 4.0.6, PHP 5)</P >fbsql_query -- Send a FrontBase query</DIV ><DIV CLASS="refsect1" ><A NAME="AEN60268" ></A ><H2 >说明</H2 >resource <B CLASS="methodname" >fbsql_query</B > ( string query [, resource link_identifier [, int batch_size]] )<BR ></BR ><P > Sends a <CODE CLASS="parameter" >query</CODE > to the currently active database on the server. </P ><P > If the query succeeds, you can call <A HREF="function.fbsql-num-rows.html" ><B CLASS="function" >fbsql_num_rows()</B ></A > to find out how many rows were returned for a SELECT statement or <A HREF="function.fbsql-affected-rows.html" ><B CLASS="function" >fbsql_affected_rows()</B ></A > to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN60287" ></A ><H2 >参数</H2 ><P > <P ></P ><DIV CLASS="variablelist" ><DL ><DT ><CODE CLASS="parameter" >query</CODE ></DT ><DD ><P > The SQL query to be executed. </P ><DIV CLASS="note" ><BLOCKQUOTE CLASS="note" ><P ><B >注意: </B > The query string shall always end with a semicolon. </P ></BLOCKQUOTE ></DIV ></DD ><DT ><CODE CLASS="parameter" > link_identifier</CODE ></DT ><DD ><P >A FrontBase link identifier returned by <A HREF="function.fbsql-connect.html" ><B CLASS="function" >fbsql_connect()</B ></A > or <A HREF="function.fbsql-pconnect.html" ><B CLASS="function" >fbsql_pconnect()</B ></A >.</P ><P >If optional and not specified, the function will try to find an open link to the FrontBase server and if no such link is found it will try to create one as if <A HREF="function.fbsql-connect.html" ><B CLASS="function" >fbsql_connect()</B ></A > was called with no arguments</P ></DD ><DT ><CODE CLASS="parameter" >batch_size</CODE ></DT ><DD ><P > </P ></DD ></DL ></DIV > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN60312" ></A ><H2 >返回值</H2 ><P > <B CLASS="function" >fbsql_query()</B > returns <TT CLASS="constant" ><B >TRUE</B ></TT > (non-zero) or <TT CLASS="constant" ><B >FALSE</B ></TT > to indicate whether or not the query succeeded. A return value of <TT CLASS="constant" ><B >TRUE</B ></TT > means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It is perfectly possible for a query to succeed but affect no rows or return no rows. </P ><P > For SELECT statements, <B CLASS="function" >fbsql_query()</B > returns a new result identifier that you can pass to <A HREF="function.fbsql-result.html" ><B CLASS="function" >fbsql_result()</B ></A >. </P ><P > <B CLASS="function" >fbsql_query()</B > will also fail and return <TT CLASS="constant" ><B >FALSE</B ></TT > if you don't have permission to access the table(s) referenced by the query. </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN60325" ></A ><H2 >范例</H2 ><P > The following query is syntactically invalid, so <B CLASS="function" >fbsql_query()</B > fails and returns <TT CLASS="constant" ><B >FALSE</B ></TT >: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN60330" ></A ><P ><B >例 1. <B CLASS="function" >fbsql_query()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$result </font><font color="#007700">= </font><font color="#0000BB">fbsql_query</font><font color="#007700">(</font><font color="#DD0000">"SELECT * WHERE 1=1"</font><font color="#007700">)<br /> or die (</font><font color="#DD0000">"Invalid query"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ><P > The following query is semantically invalid if <TT CLASS="literal" >my_col</TT > is not a column in the table <TT CLASS="literal" >my_tbl</TT >, so <B CLASS="function" >fbsql_query()</B > fails and returns <TT CLASS="constant" ><B >FALSE</B ></TT >: <TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><A NAME="AEN60339" ></A ><P ><B >例 2. <B CLASS="function" >fbsql_query()</B > example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br />$result </font><font color="#007700">= </font><font color="#0000BB">fbsql_query </font><font color="#007700">(</font><font color="#DD0000">"SELECT my_col FROM my_tbl;"</font><font color="#007700">)<br /> or die (</font><font color="#DD0000">"Invalid query"</font><font color="#007700">);<br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE > </P ></DIV ><DIV CLASS="refsect1" ><A NAME="AEN60343" ></A ><H2 >参见</H2 ><P > <P ></P ><TABLE BORDER="0" ><TBODY ><TR ><TD ><A HREF="function.fbsql-affected-rows.html" ><B CLASS="function" >fbsql_affected_rows()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.fbsql-db-query.html" ><B CLASS="function" >fbsql_db_query()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.fbsql-free-result.html" ><B CLASS="function" >fbsql_free_result()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.fbsql-result.html" ><B CLASS="function" >fbsql_result()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.fbsql-select-db.html" ><B CLASS="function" >fbsql_select_db()</B ></A ></TD ></TR ><TR ><TD ><A HREF="function.fbsql-connect.html" ><B CLASS="function" >fbsql_connect()</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.fbsql-pconnect.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.fbsql-read-blob.html" ACCESSKEY="N" >下一页</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >fbsql_pconnect</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.fbsql.html" ACCESSKEY="U" >上一级</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >fbsql_read_blob</TD ></TR ></TABLE ></DIV ></BODY ></HTML >