Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Oracle Functions : ociplogon

ociplogon

Alias of oci_pconnect (PHP 4, PHP 5, PECL oci8:1.0-1.2.4)


Code Examples / Notes » ociplogon

e dot v dot wijk

The solution for not being able to connect to an Oracle database usually is setting the right system variables (ORACLE_HOME, etc...). However, it often happens that you are still not able to connect, even though these settings are correctly set.
If this is the case, try the following:
Instead of refering to the entry in the tnsnames.ora, use the actual string from the tnsnames.ora:
$User = "john"
$Password = "doe"
$Database = "(DESCRIPTION = ADDRESS_LIST (ADDRESS = (PROTOCOL= TCP (Host= yourhost) (Port= 1526)))(CONNECT_DATA = (SID = YourTnsSID )))";
OCIPLogon($User, $Password, $Database)
I hope this is helpfull for those strugling to connect to an Oracle database.
Edwin van Wijk


m0no

If your oracle database is on a remote system within your local network and you don't want to worry about the tnsnames file you can try this.
$db = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.XX.XXX)(PORT = 1521)))(CONNECT_DATA=(SID=XXXX)))";
$c1 = ocilogon("name","password",$db);
Hope this helps someone.


steve

IF you're wondering exactly what you are dealing with, here's a brief explanation:  Oracle is NOT like mysql, which makes it very easy to connect between databases.  Oracle uses a product called sql*net to control connection between remote machines, clients and databases.  It is capable of operating on multiple different network protocols, and requires listeners to be configured for the network protocol you plan to use (usually tcp). This system has its own domain name system which rationalises database names with machines (which is why you don't have a host variable in the OCIPlogin). Configuring these listeners is not easy and requires the editing of two files tnsnames.ora and sqlnet.ora.  Even more important is to make sure that the oracle environment variable TNS_ADMIN points to the place where you put tnsnames.ora and sqlnet.ora
A good place to start reading about this is
http://www.atr.net/faq/software/FRONT_END/faqnet.htm
A more detailed version can be found at :
http://www.orafaq.net/faqnet.htm
Bear in mind that this is an incredibly complex product and not something that you should really be playing with if you don't know what you're doing.  I've seen (otherwise) experienced oracle admins baulk at configuring sql*net.  Pat solutions (like the one above) cannot be used verbatim - you will need to know and substitute several symbolic names.
HTH


kakukkfu

Better to insert needed variables into apache(!) (or your webserver - respectively) start script.
For example on UNIX systems /etc/init.d/apache would contain following lines before anything else:
#!/bin/bash
if [ -f ~oracle/.profile ]; then
       source ~oracle/.profile
fi
The ~oracle/.profile has the appropiate settings to start an Oracle database so it is always up-to-date for PHP, too. (If settings are changed, don't forget to restart your webserver.) This way you just no need to worry what to include or define for PHP.


michel

After hours of weird searching and "try an error"-games with oracle and php I´ve got my working system with connection to a remote oracle server. Yeah! Documentation is very bad for this topic and the posts in all the mailing lists are very confusing. But now...
cheers. it works!
here my working sample code (php4 on debian, oracle 8.1.5.0.2 client, oracle 8i enterprise server on win2k)
michel
<pre>
$user = "scott";
$pass = "tiger";
$tns_name = "my_service_name_in_tnsnames.ora";
// set ORACLE Dir to get the NET8 name resolver working
// tnsnames.ora has to be in $ORACLE_HOME/networking/admin/
putenv("ORACLE_HOME=/home/oracle01/app/oracle/product/8.1.5");
// log on to oracle server using data above
$db_id = OCILogon ($user, $pass, $tns_name);
</pre>


mnamdeo

<b>Connect to multiple oracle databases</b>


Easy solution
If you are using phplib, change local.inc $this->$database = <REMOTE_DATABASE_IN_TNSNAMES.ORA>;


That's it.


Change Language


Follow Navioo On Twitter
oci_bind_array_by_name
oci_bind_by_name
oci_cancel
oci_close
OCI-Collection->append
OCI-Collection->assign
OCI-Collection->assignElem
OCI-Collection->free
OCI-Collection->getElem
OCI-Collection->max
OCI-Collection->size
OCI-Collection->trim
oci_commit
oci_connect
oci_define_by_name
oci_error
oci_execute
oci_fetch_all
oci_fetch_array
oci_fetch_assoc
oci_fetch_object
oci_fetch_row
oci_fetch
oci_field_is_null
oci_field_name
oci_field_precision
oci_field_scale
oci_field_size
oci_field_type_raw
oci_field_type
oci_free_statement
oci_internal_debug
OCI-Lob->append
OCI-Lob->close
oci_lob_copy
OCI-Lob->eof
OCI-Lob->erase
OCI-Lob->export
OCI-Lob->flush
OCI-Lob->free
OCI-Lob->getBuffering
OCI-Lob->import
oci_lob_is_equal
OCI-Lob->load
OCI-Lob->read
OCI-Lob->rewind
OCI-Lob->save
OCI-Lob->saveFile
OCI-Lob->seek
OCI-Lob->setBuffering
OCI-Lob->size
OCI-Lob->tell
OCI-Lob->truncate
OCI-Lob->write
OCI-Lob->writeTemporary
OCI-Lob->writeToFile
oci_new_collection
oci_new_connect
oci_new_cursor
oci_new_descriptor
oci_num_fields
oci_num_rows
oci_parse
oci_password_change
oci_pconnect
oci_result
oci_rollback
oci_server_version
oci_set_prefetch
oci_statement_type
ocibindbyname
ocicancel
ocicloselob
ocicollappend
ocicollassign
ocicollassignelem
ocicollgetelem
ocicollmax
ocicollsize
ocicolltrim
ocicolumnisnull
ocicolumnname
ocicolumnprecision
ocicolumnscale
ocicolumnsize
ocicolumntype
ocicolumntyperaw
ocicommit
ocidefinebyname
ocierror
ociexecute
ocifetch
ocifetchinto
ocifetchstatement
ocifreecollection
ocifreecursor
ocifreedesc
ocifreestatement
ociinternaldebug
ociloadlob
ocilogoff
ocilogon
ocinewcollection
ocinewcursor
ocinewdescriptor
ocinlogon
ocinumcols
ociparse
ociplogon
ociresult
ocirollback
ocirowcount
ocisavelob
ocisavelobfile
ociserverversion
ocisetprefetch
ocistatementtype
ociwritelobtofile
ociwritetemporarylob
eXTReMe Tracker