Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Excel output of Oracle data

    I need PHP to show me an Excel output of my Oracle 9i database.

    The below would work for MySQL database but how would I do it for Oracle??


    Code:
    <?php 
    define(db_host, "localhost"); 
    define(db_user, "excel"); 
    define(db_pass, "spreadsheet"); 
    define(db_link, mysql_connect(db_host,db_user,db_pass)); 
    define(db_name, "export2excel"); 
    mysql_select_db(db_name); 
    
    $select = "SELECT * FROM TABLE_NAME";                 
    $export = mysql_query($select); 
    $fields = mysql_num_fields($export); 
    for ($i = 0; $i < $fields; $i++) { 
        $header .= mysql_field_name($export, $i) . "\t"; 
    } 
    while($row = mysql_fetch_row($export)) { 
        $line = ''; 
        foreach($row as $value) {                                             
            if ((!isset($value)) OR ($value == "")) { 
                $value = "\t"; 
            } else { 
                $value = str_replace('"', '""', $value); 
                $value = '"' . $value . '"' . "\t"; 
            } 
            $line .= $value; 
        } 
        $data .= trim($line)."\n"; 
    } 
    $data = str_replace("\r","",$data); 
    if ($data == "") { 
        $data = "\n(0) Records Found!\n";                         
    } 
    header("Content-type: application/x-msdownload"); 
    header("Content-Disposition: attachment; filename=extraction.xls"); 
    header("Pragma: no-cache"); 
    header("Expires: 0"); 
    print "$header\n$data";  
    ?>

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Use the oci functions.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •