[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

Connecting to Oracle using PHP - retrieving data

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
awarraic
Asked:
awarraic
1 Solution
 
tlovieCommented:
wouldn't you do it in the select statement like this:

'SELECT * FROM schema.TableName'
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Tackle projects and never again get stuck behind a technical roadblock.
Join Now