 |
| 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
|
|
|
|

June 4th, 2004, 01:31 AM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

June 4th, 2004, 05:58 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 7th, 2004, 08:20 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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: $row[line]</td>";
echo " <td class=text8Arial11> <b>Invoice No: $row[no]</td>";
echo "</tr>";
echo " <td class=text8Arial1><b>Pos</b></td>";
echo " <td class=text8Arial1> <b>Stock</td>";
echo " <td class=text8Arial1><b> QTY</b></td>";
echo " <td class=text8Arial1><b> UOM</b></td>";
echo " <td class=text8Arial1><b> Unit Price</b></td>";
echo " <td class=text8Arial1><b> Amount</b></td>";
echo " <td class=text8Arial1><b> Total</b></td>";
echo "</tr>";
echo " <td class=text8Arial1>$row[po1]</td>";
echo " <td class=text8Arial> <TEXTAREA class=text8Arial11 name=\"stock1\" rows=5 cols=120>$row[stock1]</TEXTAREA></td>";
echo " <td class=text8Arial1> $row[qty1]</td>";
echo " <td class=text8Arial1> $row[uom1]</td>";
echo " <td class=text8Arial1> $row[pri1]</td>";
echo " <td class=text8Arial1> $row[amo1]</td>";
echo " <td class=text8Arial1> $row[total]</td>";
echo "</tr>";
}
Thanks in advance,
molly
|
|

June 8th, 2004, 10:35 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 8th, 2004, 07:35 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

June 8th, 2004, 08:04 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
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
::::::::::::::::::::::::::::::::::::::::::
|
|

June 8th, 2004, 09:08 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 8th, 2004, 09:21 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
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:
[email protected]
You can also subscribe to this list from:
http://pear.php.net/support.php
Regards,
Rich
::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
|
|

June 15th, 2004, 10:52 PM
|
|
Authorized User
|
|
Join Date: Apr 2004
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<?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.
|
|

June 16th, 2004, 06:23 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|
 |