Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old June 4th, 2004, 01:31 AM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default PHP VS Oracle

hi,
i have download the PEAR module and create the DB.php, PEAR.php, common.php and oci8.php.

When i run my system at browser, it dispaly error msg:
DB ERROR connect failed.:(

Please give me advise, which part of among the .php file that i need to modify and make change?

i use PHP4.3.4 Oracle 8 IIS 5.0

Thanks in advance.

  #2 (permalink)  
Old June 4th, 2004, 05:58 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The page where you are making the connection to the database, by the look of it :). It will probably contain something along the lines of:

// DB connection settings
$user = 'local_user_name';
$pass = 'local_password';
$host = 'localhost';
$db_name = 'databasename';
// local DB connection settings

// set up the data source name connection string
$dsn = "mysql://$user:$pass@$host/$db_name";

// make the connection to the DB
$db = DB::connect($dsn);

// check a valid connection was made
if (DB::isError($db)) {
    die($db->getMessage()); //<- This is what is printing your error message out.
}

Give it the correct username and password for someone who has the right to log in to your Oracle database from localhost, and you should be good to go.

Take it easy,
Dan
  #3 (permalink)  
Old June 7th, 2004, 08:20 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi Dan,

I want change the Mysql dbase function to Oracle 8 function. So, how to change this code to Oracle 8?I know it begin with oci.

Attach code:

//query database
$query = "SELECT * FROM item WHERE no = '$no'";
$result = mysql_query($query, $connection)or die(mysql_error());
$rows = mysql_num_rows($result);

//display all entries

              for ( $i=0; $i<$rows; $i++ )
        {
            $row =mysql_fetch_array($result);

          echo " <td class=text8Arial1><b>Line:&nbsp;$row[line]</td>";
              echo " <td class=text8Arial11>&nbsp;&nbsp;<b>Invoice No: $row[no]</td>";
              echo "</tr>";
              echo " <td class=text8Arial1><b>Pos</b></td>";
          echo " <td class=text8Arial1>&nbsp;<b>Stock</td>";
              echo " <td class=text8Arial1><b>&nbsp;&nbsp;QTY</b></td>";
              echo " <td class=text8Arial1><b>&nbsp;&nbsp;UOM</b></td>";
              echo " <td class=text8Arial1><b>&nbsp;&nbsp;Unit Price</b></td>";
              echo " <td class=text8Arial1><b>&nbsp;Amount</b></td>";
              echo " <td class=text8Arial1><b>&nbsp;Total</b></td>";
              echo "</tr>";

          echo " <td class=text8Arial1>$row[po1]</td>";
          echo " <td class=text8Arial>&nbsp;<TEXTAREA class=text8Arial11 name=\"stock1\" rows=5 cols=120>$row[stock1]</TEXTAREA></td>";
              echo " <td class=text8Arial1>&nbsp;&nbsp;$row[qty1]</td>";
              echo " <td class=text8Arial1>&nbsp;&nbsp;$row[uom1]</td>";
              echo " <td class=text8Arial1>&nbsp;&nbsp;$row[pri1]</td>";
              echo " <td class=text8Arial1>&nbsp;$row[amo1]</td>";
              echo " <td class=text8Arial1>&nbsp;$row[total]</td>";
              echo "</tr>";
            }

Thanks in advance,
molly

  #4 (permalink)  
Old June 8th, 2004, 10:35 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, you'd probably use a DSN like:

$dsn = "oci8://$user:$pass@$host/$db_name";

After that, most of your work would be via the standard procedure calls in DB_common, I'd guess. Something like (Translating the top of your code to DB::PEAR):

$query = "SELECT * FROM item WHERE no = '$no'";
$result = ($db->query($query, $connection)or die($result->getMessage()));
$rows = $result->numRows($result);

//display all entries

    for ( $i=0; $i<$rows; $i++ )
        {
            $row = $result->fetchRow();
...and so on.

That's a strict translation, although saying:

while($row = $result->fetchRow()){

Would do away with having to find out the number of rows and then ahing to use a for loop to go through them all.

HTH
Dan
  #5 (permalink)  
Old June 8th, 2004, 07:35 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi,
I use Oracle8oci function, not DSN. So, what differences?

Attach code:
require_once("DB.php");
$connection = OCILogon ("prod","prod");
//build and issue query
$stmt = OCIParse($connection, "select * from bill where invno ='$_POST[invno]'");
$result = OCIExecute($stmt, OCI_DEFAULT);

** $rows = $result->numRows($result);**
should changed:
1. $row = OCIRowCount($stmt); OR
2. $row = OCIFetchStatement($stmt, $results, OCI_FETCHSTATEMENT_BY_ROW);

Then, next line how to change it?
** $row = $result->fetchRow(); **

Thanks in advance,
molly.

  #6 (permalink)  
Old June 8th, 2004, 08:04 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Quote:
quote:
I use Oracle8oci function, not DSN. So, what differences?
You started out talking about PEAR DB, right? The PEAR DB package is an object that allows connection to any one of 13 different databases, actually more than that, it really provides 13 different drivers and umbrellas them into a single package.

fbsql, ifx, mssql, mysqli, odbc, sqlite, dbase, ibase, msql, mysql, oci8, pgsql and sybase.

This is good because it provides DB abstraction, so your code isn't tied to a single database. You just have to use generic, widely implemented, standardized SQL in your applications as opposed to proprietary SQL to reap the full benefits.

The DSN Daniel is talking about is a URI abstraction that PEAR DB uses to connect to the particular database that you specify.

$dsn = "oci8://$user:$pass@$host/$db_name";

This uses the Oracle 8 driver of PEAR DB.

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
  #7 (permalink)  
Old June 8th, 2004, 09:08 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

Hi,
I have try use a DSN as Daniel mention but when i run at browser,it display:
DB ERROR Unknown error.

So, my consultant advise me to rewrite the code using oci8 function and have give me some example because Oracle and PHP stil new for me.Then, have some code line I don't know how to change it (previous post).

Give me some advise to solve this problem. I had waste many time on changing my code. My system already can connect to Mysql dbase(without PEAR DB)but now I want it can success connect to Oracle dbase. Have any fast and easy for me understand way?

Thanks in advance,
molly


  #8 (permalink)  
Old June 8th, 2004, 09:21 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I would suggest posting your question to the PEAR-GENERAL mailing list, many of the package authors subscribe to this list and you're more likely to get help there.

The address is:
pear-general@lists.php.net

You can also subscribe to this list from:
http://pear.php.net/support.php

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
  #9 (permalink)  
Old June 15th, 2004, 10:52 PM
Authorized User
 
Join Date: Apr 2004
Location: malacca, malacca, Malaysia.
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to junemo
Default

<?php
require_once 'DB.php'; //require the PEAR::DB classes.

$db_engine = 'oci8';
$db_user = 'prod';
$db_pass = 'prod';
$db_host = 'ptmn';
$db_name = 'prod';

$dsn = $db_engine.'://'.$db_user.':'.$db_pass.'@'.$db_host.'/'.$db_name;

$db = DB::connect($dsn, TRUE);
/* assign database object in $db_object, if the connection fails $db_object will contain
the error message. */

// If $db_object contains an error print out the
// error and exit.

if(DB::isError($db)) {
    die($db->getMessage());
}

$db->setFetchMode(DB_FETCHMODE_ASSOC);

$db->disconnect(); // Close the connection.

?>

I get this error msg:
DB Error: unknown error

What solution can I do?

Thanks in advance.

  #10 (permalink)  
Old June 16th, 2004, 06:23 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why are you passing "TRUE" as the second parameter to connect(), as a matter of interest? That's quite an old-fashioned way of connecting. Wouldn't it be better to assign an array of options more explicitly, such as:

$options = array(
    'debug' => 2,
    'portability' => DB_PORTABILITY_ALL,
);
...and then say:

$db =& DB::connect($dsn, $options);

Just a suggestion.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to oracle from PHP paragajoshi PHP Databases 2 November 16th, 2011 05:26 PM
Connecting to Oracle with PHP atcs2152 PHP Databases 0 December 16th, 2005 08:57 AM
inserting into oracle using php cblake PHP Databases 1 May 26th, 2005 03:01 AM
php oracle select timbal25 PHP Databases 1 July 2nd, 2004 06:46 AM
oracle and php shakim Oracle 0 September 24th, 2003 09:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.