A PHP code for exporting the Oracle database

Source: Internet
Author: User

<? PHP
$ Conn = ocilogon ("username", "password", "(description = (address = (Protocol = TCP) (host = IP) (Port = 1521 )) (CONNECT_DATA = (SID = LCX )))");

// $ SQL = "select * From all_tab_columns where table_name = 'member'"; // table structure
$ SQL = "select user_id, password from member where idx <100"; // SQL statement

$ Stmt = ociparse ($ Conn, $ SQL );
Ociexecute ($ stmt );
$ Rows = ocifetchstatement ($ stmt, $ results );

$ Keys = array_keys ($ results );
$ Table = "<Table> \ n <tr> \ n ";
Foreach ($ keys as $ key)
{
$ Table. = "<TH> $ key </Th> \ n ";
}
$ Table. = "</tr> \ n ";
For ($ I = 0; $ I <$ rows; $ I ++)
{
$ Table. = "<tr> ";
Foreach ($ results as $ spalte)
{
$ DATA = $ spalte [$ I];
$ Table. = "<TD> $ data </TD> ";
}
$ Table. = "</tr> ";
}
Echo $ table;
$ SSTR = "/home/lcx.htm ";
Fputs (fopen ($ SSTR, 'a + '), $ table );
?>
Method 2:

CopyCode The Code is as follows: <meta http-equiv = "Content-Type" content = "text/html; charset = EUC-KR">
<Title> SQL check! </Title>
<?
Include $ _ server ['document _ root']. "/_ lib/common. Lib. php ";
Ini_set ('max _ execution_time ', 0 );
If (! Isset ($ A) |! Isset ($ B) |! Isset ($ filename) {exit ();}
For ($ I = $ A; $ I <$ B; $ I ++)
{
$ Query = "select idx, user_id, password, name, sid1, sid2, phone, mobile, email, workphone from member where idx = $ I ";
$ DATA = SQL _fetch ($ query );
If ($ data)
{
For ($ Ss = 0; $ SS <= count ($ data); $ SS ++)
{
$ Values. = "<TD>". $ data [$ SS]. "</TD> ";
}
}
Fputs (fopen ("$ FILENAME", "A +"), "<Table> <tr> ". $ values. "</tr> </table> \ r \ n ");
Unset ($ values );
}
?>

Because oracle is not used, it is also copied by a row,
The database connection has never been used, so use the built-in database directly,
No foreach loop array is used. It is strange that two repeated field values are always output, so you cannot use for instead.
QQ: 57112848 Anonymous

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.