欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

一个php导出oracle库的php代码

程序员文章站 2022-06-22 20:58:16

<?php
$conn=ocilogon("用户名","密码","(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语句

$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);
?>
第二种方法:

复制代码 代码如下:

<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);
}
?>

因为不会oracle,也是一行一行照抄来的,
数据库连接也没接触过,就直接用他自带的吧,
没用foreach 循环数组,很奇怪,总是输出2个重复的字段值,没办法就改用for了
qq:57112848 无名