Solved

Connecting to Oracle using PHP - retrieving data

Posted on 2011-02-16
1
378 Views
Last Modified: 2012-05-11
I am trying to connect to oracle through php code.
I tested the connection to the database and that seems to be OK but having problem connecting to the table. I am MS SQL Server/Mysql user and never used schema's in there. In Oracle table that I am trying to connect lives in a Schema. How do I pass the correct Schema info in PHP. That's the only thing I assume is missing in this puzzle.

Structure of my Oracle database:

Server>Database>Schema>Table
<?php
	
	$conn = oci_connect ( 'username', 'password', 'ServerName/DatabaseName') or exit (mysql_error());
	//mysql_select_db('test');
	
	// only select the columns you need, thus reducing the work the DBMS has to do.
	$query = "SELECT * FROM TableName";
	// execute the query
	$results = oci_parse ($conn, 'SELECT * FROM TableName'); //or exit(oci_error());
	
	echo "test 1";
	oci_execute($results);
	
	echo "end test 1";
	
	// check for the number of rows returned before doing any further actions.
	if ($row = oci_fetch_array($results) == 0){
	exit("Nothing to Show Here");
	}

?>


Errors/Warnings:
1 - "Table or view doesn't exist" at the line: 
$results = oci_parse ($conn, 'SELECT * FROM TableName');

2 - "ORA-24374: define not done before fetch or execute and fetch" at line: 
if ($row = oci_fetch_array($results) == 0){

Open in new window

0
Comment
Question by:awarraic
1 Comment
 
LVL 7

Accepted Solution

by:
tlovie earned 500 total points
ID: 34908771
wouldn't you do it in the select statement like this:

'SELECT * FROM schema.TableName'
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question