Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a34ed6838d4b29d38abd504392a4a797 > files > 412

php-manual-es-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>dbx_query</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Manual de PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="dbx functions"
HREF="ref.dbx.html"><LINK
REL="PREVIOUS"
TITLE="dbx_escape_string"
HREF="function.dbx-escape-string.html"><LINK
REL="NEXT"
TITLE="dbx_sort"
HREF="function.dbx-sort.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></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"
>Manual de PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.dbx-escape-string.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.dbx-sort.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.dbx-query"
></A
>dbx_query</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN13215"
></A
><P
>    (PHP 4 &#62;= 4.0.6)</P
>dbx_query&nbsp;--&nbsp;Send a query and fetch all results (if any)</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN13218"
></A
><H2
>Description</H2
>object <B
CLASS="methodname"
>dbx_query</B
> ( object link_identifier, string sql_statement [, long flags])<BR
></BR
><P
>&#13;     <B
CLASS="function"
>dbx_query()</B
> returns an object or <TT
CLASS="literal"
>1</TT
> 
     on success, and <TT
CLASS="literal"
>0</TT
> on failure. The result object is 
     returned only if the query given in <TT
CLASS="parameter"
><I
>sql_statement</I
></TT
>
     produces a result set. 
    </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN13237"
></A
><P
><B
>Ejemplo 1. How to handle the returned value</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
$link   = dbx_connect(DBX_ODBC, "", "db", "username", "password")
    or die("Could not connect");

$result = dbx_query($link, 'SELECT id, parentid, description FROM table');

if ( is_object($result) ) {
    // ... do some stuff here, see detailed examples below ...
    // first, print out field names and types 
    // then, draw a table filled with the returned field values
}
else if ( $result == 1 ) {
    echo("Query executed successfully, but no result set returned");
}
else {
    exit("Query failed");
}

dbx_close($link);
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
><P
>&#13;     The <TT
CLASS="parameter"
><I
>flags</I
></TT
> parameter is used to control the amount of
     information that is returned. It may be any combination of the following 
     constants with the bitwise OR operator (|). The DBX_COLNAMES_* flags 
     override the dbx.colnames_case setting from <TT
CLASS="filename"
>php.ini</TT
>.
     <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><TT
CLASS="constant"
><B
>DBX_RESULT_INDEX</B
></TT
></DT
><DD
><P
>&#13;         It is <SPAN
CLASS="emphasis"
><I
CLASS="emphasis"
>always</I
></SPAN
> set, that is, the returned object 
         has a <SPAN
CLASS="property"
>data</SPAN
> property which is a 2 dimensional
         array indexed numerically. For example, in the expression 
         <TT
CLASS="literal"
>data[2][3]</TT
> <TT
CLASS="literal"
>2</TT
> stands for the row
         (or record) number and <TT
CLASS="literal"
>3</TT
> stands for the column 
         (or field) number. The first row and column are indexed at 0.
        </P
><P
>&#13;         If <TT
CLASS="constant"
><B
>DBX_RESULT_ASSOC</B
></TT
> is also specified, the 
         returning object contains the information related to 
         <TT
CLASS="constant"
><B
>DBX_RESULT_INFO</B
></TT
> too, even if it was not specified. 
        </P
></DD
><DT
><TT
CLASS="constant"
><B
>DBX_RESULT_INFO</B
></TT
></DT
><DD
><P
>&#13;         It provides info about columns, such as field names and field types.
        </P
></DD
><DT
><TT
CLASS="constant"
><B
>DBX_RESULT_ASSOC</B
></TT
></DT
><DD
><P
>&#13;         It effects that the field values can be accessed with the respective 
         column names used as keys to the returned object's 
         <SPAN
CLASS="property"
>data</SPAN
> property.
        </P
><P
>&#13;         Associated results are actually references to the numerically indexed 
         data, so modifying <TT
CLASS="literal"
>data[0][0]</TT
> causes that
         <TT
CLASS="literal"
>data[0]['field_name_for_first_column']</TT
> is modified
         as well.
        </P
></DD
><DT
><TT
CLASS="constant"
><B
>DBX_COLNAMES_UNCHANGED</B
></TT
> (available from PHP 4.3.0)</DT
><DD
><P
>&#13;         The case of the returned column names will not be changed.
        </P
></DD
><DT
><TT
CLASS="constant"
><B
>DBX_COLNAMES_UPPERCASE</B
></TT
> (available from PHP 4.3.0)</DT
><DD
><P
>&#13;         The case of the returned column names will be changed to 
         uppercase.
        </P
></DD
><DT
><TT
CLASS="constant"
><B
>DBX_COLNAMES_LOWERCASE</B
></TT
> (available from PHP 4.3.0)</DT
><DD
><P
>&#13;         The case of the returned column names will be changed to 
         lowercase.
        </P
></DD
></DL
></DIV
>
     Note that <TT
CLASS="constant"
><B
>DBX_RESULT_INDEX</B
></TT
> is always used, regardless 
     of the actual value of <TT
CLASS="parameter"
><I
>flags</I
></TT
> parameter. This means 
     that the following combinations is effective only:
     <P
></P
><UL
><LI
><P
>&#13;        <TT
CLASS="constant"
><B
>DBX_RESULT_INDEX</B
></TT
>
       </P
></LI
><LI
><P
>&#13;        <TT
CLASS="constant"
><B
>DBX_RESULT_INDEX</B
></TT
> |
        <TT
CLASS="constant"
><B
>DBX_RESULT_INFO</B
></TT
>
       </P
></LI
><LI
><P
>&#13;        <TT
CLASS="constant"
><B
>DBX_RESULT_INDEX</B
></TT
> |
        <TT
CLASS="constant"
><B
>DBX_RESULT_INFO</B
></TT
> |
        <TT
CLASS="constant"
><B
>DBX_RESULT_ASSOC</B
></TT
> - this is the default, if 
        <TT
CLASS="parameter"
><I
>flags</I
></TT
> is not specified.
       </P
></LI
></UL
>
    </P
><P
>&#13;     The returing <TT
CLASS="varname"
>object</TT
> has four or five
     properties depending on <TT
CLASS="parameter"
><I
>flags</I
></TT
>:
     <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><SPAN
CLASS="property"
>handle</SPAN
></DT
><DD
><P
>&#13;         It is a valid handle for the connected database, and as such it can be
         used in module specific functions (if required).
         <DIV
CLASS="informalexample"
><A
NAME="AEN13311"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="programlisting"
>$result = dbx_query ($link, "SELECT id FROM table");
mysql_field_len ($result-&#62;handle, 0);</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
        </P
></DD
><DT
><SPAN
CLASS="property"
>cols</SPAN
> and <SPAN
CLASS="property"
>rows</SPAN
></DT
><DD
><P
>&#13;         These contain the number of columns (or fields) and rows (or records)
         respectively.
         <DIV
CLASS="informalexample"
><A
NAME="AEN13319"
></A
><P
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$result = dbx_query ($link, 'SELECT id FROM table');
echo $result-&#62;rows; // number of records
echo $result-&#62;cols; // number of fields</PRE
></TD
></TR
></TABLE
><P
></P
></DIV
>
        </P
></DD
><DT
><SPAN
CLASS="property"
>info</SPAN
> (optional)</DT
><DD
><P
>&#13;         It is returned only if either <TT
CLASS="constant"
><B
>DBX_RESULT_INFO</B
></TT
> or
         <TT
CLASS="constant"
><B
>DBX_RESULT_ASSOC</B
></TT
> is specified in the
         <TT
CLASS="parameter"
><I
>flags</I
></TT
> parameter. It is a 2 dimensional array,
         that has two named rows (<TT
CLASS="literal"
>name</TT
> and 
         <TT
CLASS="literal"
>type</TT
>) to retrieve column information.
        </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN13331"
></A
><P
><B
>Ejemplo 2. lists each field's name and type</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$result = dbx_query ($link, 'SELECT id FROM table',
                     DBX_RESULT_INDEX | DBX_RESULT_INFO);

for ($i = 0; $i &#60; $result-&#62;cols; $i++ ) {
    echo $result-&#62;info['name'][$i] . "\n";
    echo $result-&#62;info['type'][$i] . "\n";  
}</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DD
><DT
><SPAN
CLASS="property"
>data</SPAN
></DT
><DD
><P
>&#13;         This property contains the actual resulting data, possibly associated 
         with column names as well depending on <TT
CLASS="parameter"
><I
>flags</I
></TT
>.
         If <TT
CLASS="constant"
><B
>DBX_RESULT_ASSOC</B
></TT
> is set, it is possible to use
         <TT
CLASS="literal"
>$result-&#62;data[2]["field_name"]</TT
>.
        </P
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN13342"
></A
><P
><B
>Ejemplo 3. outputs the content of data property into HTML table</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>$result = dbx_query ($link, 'SELECT id, parentid, description FROM table');

echo "&#60;table&#62;\n";
foreach ( $result-&#62;data as $row ) {
    echo "&#60;tr&#62;\n";
    foreach ( $row as $field ) {
        echo "&#60;td&#62;$field&#60;/td&#62;";
    }
    echo "&#60;/tr&#62;\n";
}
echo "&#60;/table&#62;\n";</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
></DD
></DL
></DIV
>
    </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>Nota: </B
>
      Always refer to the module-specific documentation as well.
     </P
><P
>&#13;      Column names for queries on an Oracle database are returned
      in lowercase.
     </P
></BLOCKQUOTE
></DIV
><P
>&#13;     See also: <A
HREF="function.dbx-escape-string.html"
><B
CLASS="function"
>dbx_escape_string()</B
></A
> and <A
HREF="function.dbx-connect.html"
><B
CLASS="function"
>dbx_connect()</B
></A
>.
    </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.dbx-escape-string.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Inicio</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.dbx-sort.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>dbx_escape_string</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.dbx.html"
ACCESSKEY="U"
>Subir</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>dbx_sort</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>