Sophie

Sophie

distrib > Mandriva > 2008.1 > x86_64 > by-pkgid > 05cd670d8a02b2b4a0ffb1756f2e8308 > files > 3986

php-manual-zh-5.2.4-1mdv2008.1.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>px_insert_record</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REL="HOME"
TITLE="PHP 手册"
HREF="index.html"><LINK
REL="UP"
TITLE="Paradox File Access"
HREF="ref.paradox.html"><LINK
REL="PREVIOUS"
TITLE="px_get_value"
HREF="function.px-get-value.html"><LINK
REL="NEXT"
TITLE="px_new"
HREF="function.px-new.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.px-get-value.html"
ACCESSKEY="P"
>上一页</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.px-new.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.px-insert-record"
></A
>px_insert_record</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN167766"
></A
><P
>    (PECL)</P
>px_insert_record&nbsp;--&nbsp;Inserts record into paradox database</DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167769"
></A
><H2
>说明</H2
>int <B
CLASS="methodname"
>px_insert_record</B
> ( resource pxdoc, array data )<BR
></BR
><P
>&#13;   Inserts a new record into the database. The record is not necessarily
   inserted at the end of the database, but may be inserted at any
   position depending on where the first free slot is found.
  </P
><P
>&#13;   The record data is passed as an array of field values. The elements in
   the array must correspond to the fields in the database. If the array
   has less elements than fields in the database, the remaining fields
   will be set to null.
  </P
><P
>&#13;   Most field values can be passed as its equivalent php type e.g. a long
   value is used for fields of type PX_FIELD_LONG, PX_FIELD_SHORT and
   PX_FIELD_AUTOINC, a double values is used for fields of type
   PX_FIELD_CURRENCY and PX_FIELD_NUMBER.
   Field values for blob and alpha fields are passed as strings.
  </P
><P
>&#13;   Fields of type PX_FIELD_TIME and PX_FIELD_DATE both require a long
   value. In the first case this is the number of milliseconds since
   midnight. In the second case this is the number of days since 1.1.0000.
   Below there are two examples to convert the current date or timestamp
   into a value suitable for one of paradox's date/time fields.
  </P
><DIV
CLASS="note"
><BLOCKQUOTE
CLASS="note"
><P
><B
>注意: </B
>
    This function is only available if pxlib &#62;= 0.6.0 is used.
   </P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167786"
></A
><H2
>参数</H2
><P
>&#13;   <P
></P
><DIV
CLASS="variablelist"
><DL
><DT
><CODE
CLASS="parameter"
>pxdoc</CODE
></DT
><DD
><P
>&#13;       Resource identifier of the paradox database
       as returned by <A
HREF="function.px-new.html"
><B
CLASS="function"
>px_new()</B
></A
>.
      </P
></DD
><DT
><CODE
CLASS="parameter"
>data</CODE
></DT
><DD
><P
>&#13;       Associated or indexed array containing the field values as e.g.
       returned by <A
HREF="function.px-retrieve-record.html"
><B
CLASS="function"
>px_retrieve_record()</B
></A
>.
      </P
></DD
></DL
></DIV
>
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167802"
></A
><H2
>返回值</H2
><P
>&#13;   Returns <TT
CLASS="constant"
><B
>FALSE</B
></TT
> on failure or the record number in case of success.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167806"
></A
><H2
>范例</H2
><P
>&#13;   <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN167809"
></A
><P
><B
>例 1. Set the date/time fields in a paradox database to the current
    date/time</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><code><font color="#000000">
<font color="#0000BB">&lt;?php<br />$px </font><font color="#007700">= </font><font color="#0000BB">px_new</font><font color="#007700">();<br /></font><font color="#0000BB">$fp </font><font color="#007700">= </font><font color="#0000BB">fopen</font><font color="#007700">(</font><font color="#DD0000">"test.db"</font><font color="#007700">, </font><font color="#DD0000">"w+"</font><font color="#007700">);<br /></font><font color="#0000BB">px_create_fp</font><font color="#007700">(</font><font color="#0000BB">$px</font><font color="#007700">, </font><font color="#0000BB">$fp</font><font color="#007700">, array(array(</font><font color="#DD0000">"timestamp"</font><font color="#007700">, </font><font color="#DD0000">"@"</font><font color="#007700">), array(</font><font color="#DD0000">"time"</font><font color="#007700">, </font><font color="#DD0000">"T"</font><font color="#007700">), array(</font><font color="#DD0000">"date"</font><font color="#007700">, </font><font color="#DD0000">"D"</font><font color="#007700">)));<br /><br /></font><font color="#0000BB">$curdate </font><font color="#007700">= </font><font color="#0000BB">getdate</font><font color="#007700">();<br /></font><font color="#0000BB">$jd </font><font color="#007700">= </font><font color="#0000BB">gregoriantojd</font><font color="#007700">(</font><font color="#0000BB">$curdate</font><font color="#007700">[</font><font color="#DD0000">"mon"</font><font color="#007700">], </font><font color="#0000BB">$curdate</font><font color="#007700">[</font><font color="#DD0000">"mday"</font><font color="#007700">], </font><font color="#0000BB">$curdate</font><font color="#007700">[</font><font color="#DD0000">"year"</font><font color="#007700">]);<br /></font><font color="#0000BB">$days </font><font color="#007700">= </font><font color="#0000BB">$jd </font><font color="#007700">- </font><font color="#0000BB">1721425</font><font color="#007700">; </font><font color="#FF8000">/* Number of days between 1.1.4714 b.c. and 1.1.0000 */<br /></font><font color="#0000BB">$secs </font><font color="#007700">= </font><font color="#0000BB">$curdate</font><font color="#007700">[</font><font color="#DD0000">"hours"</font><font color="#007700">]*</font><font color="#0000BB">3600 </font><font color="#007700">+ </font><font color="#0000BB">$curdate</font><font color="#007700">[</font><font color="#DD0000">"minutes"</font><font color="#007700">]*</font><font color="#0000BB">60 </font><font color="#007700">+ </font><font color="#0000BB">$curdate</font><font color="#007700">[</font><font color="#DD0000">"seconds"</font><font color="#007700">];<br /></font><font color="#0000BB">px_insert_record</font><font color="#007700">(</font><font color="#0000BB">$px</font><font color="#007700">, array(</font><font color="#0000BB">$days</font><font color="#007700">*</font><font color="#0000BB">86400000.0 </font><font color="#007700">+ </font><font color="#0000BB">$secs</font><font color="#007700">*</font><font color="#0000BB">1000.0</font><font color="#007700">, </font><font color="#0000BB">$secs</font><font color="#007700">*</font><font color="#0000BB">1000.0</font><font color="#007700">, </font><font color="#0000BB">$days</font><font color="#007700">));<br /><br /></font><font color="#0000BB">$curtimestamp </font><font color="#007700">= </font><font color="#0000BB">microtime</font><font color="#007700">(</font><font color="#0000BB">true</font><font color="#007700">);<br /></font><font color="#0000BB">$days </font><font color="#007700">= (int) (</font><font color="#0000BB">$curtimestamp</font><font color="#007700">/</font><font color="#0000BB">86400</font><font color="#007700">);<br /></font><font color="#0000BB">$secs </font><font color="#007700">= </font><font color="#0000BB">$curtimestamp </font><font color="#007700">- (</font><font color="#0000BB">$days </font><font color="#007700">* </font><font color="#0000BB">86400.0</font><font color="#007700">);<br /></font><font color="#0000BB">$days </font><font color="#007700">+= </font><font color="#0000BB">2440588</font><font color="#007700">; </font><font color="#FF8000">/* Number of days between 1.1.4714 b.c. and 1.1.1970 */<br /></font><font color="#0000BB">$days </font><font color="#007700">-= </font><font color="#0000BB">1721425</font><font color="#007700">; </font><font color="#FF8000">/* Number of days between 1.1.4714 b.c. and 1.1.0000 */<br /></font><font color="#0000BB">px_insert_record</font><font color="#007700">(</font><font color="#0000BB">$px</font><font color="#007700">, array(</font><font color="#0000BB">$days</font><font color="#007700">*</font><font color="#0000BB">86400000.0 </font><font color="#007700">+ </font><font color="#0000BB">$secs</font><font color="#007700">*</font><font color="#0000BB">1000.0</font><font color="#007700">, </font><font color="#0000BB">$secs</font><font color="#007700">*</font><font color="#0000BB">1000.0</font><font color="#007700">, </font><font color="#0000BB">$days</font><font color="#007700">));<br />for(</font><font color="#0000BB">$i</font><font color="#007700">=</font><font color="#0000BB">0</font><font color="#007700">; </font><font color="#0000BB">$i</font><font color="#007700">&lt;</font><font color="#0000BB">2</font><font color="#007700">; </font><font color="#0000BB">$i</font><font color="#007700">++) {<br />&nbsp;&nbsp;&nbsp;&nbsp;</font><font color="#0000BB">$rec </font><font color="#007700">= </font><font color="#0000BB">px_retrieve_record</font><font color="#007700">(</font><font color="#0000BB">$px</font><font color="#007700">, </font><font color="#0000BB">$i</font><font color="#007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#0000BB">px_timestamp2string</font><font color="#007700">(</font><font color="#0000BB">$px</font><font color="#007700">, </font><font color="#0000BB">$rec</font><font color="#007700">[</font><font color="#DD0000">"timestamp"</font><font color="#007700">], </font><font color="#DD0000">"n/d/Y H:i:s"</font><font color="#007700">).</font><font color="#DD0000">"\n"</font><font color="#007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo </font><font color="#0000BB">px_date2string</font><font color="#007700">(</font><font color="#0000BB">$px</font><font color="#007700">, </font><font color="#0000BB">$rec</font><font color="#007700">[</font><font color="#DD0000">"date"</font><font color="#007700">], </font><font color="#DD0000">"n/d/Y"</font><font color="#007700">).</font><font color="#DD0000">"\n"</font><font color="#007700">;<br />}<br /></font><font color="#0000BB">px_close</font><font color="#007700">(</font><font color="#0000BB">$px</font><font color="#007700">);<br /></font><font color="#0000BB">px_delete</font><font color="#007700">(</font><font color="#0000BB">$px</font><font color="#007700">);<br /></font><font color="#0000BB">?&gt;</font>
</font>
</code></TD
></TR
></TABLE
><P
>上例将输出:</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="screen"
>2/21/2006 21:42:30
2/21/2006
2/21/2006 20:42:30
2/21/2006</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
  </P
><P
>&#13;    The Julian day count as passed to <A
HREF="function.jdtogregorian.html"
><B
CLASS="function"
>jdtogregorian()</B
></A
>
    has a different base of 1.1.4714 b.c. and must therefore be calculated
    by adding 1721425 to the day count used in the paradox file. Turning the
    day count into a timestamp is easily done by multiplying with 86400000.0
    to obtain milli seconds.
  </P
></DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN167816"
></A
><H2
>参见</H2
><P
>&#13;    <A
HREF="function.px-update-record.html"
><B
CLASS="function"
>px_update_record()</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.px-get-value.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.px-new.html"
ACCESSKEY="N"
>下一页</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>px_get_value</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.paradox.html"
ACCESSKEY="U"
>上一级</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>px_new</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>