<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=PHP-llibreria_OCI8</id>
	<title>PHP-llibreria OCI8 - Historial de revisió</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.joanillo.org/index.php?action=history&amp;feed=atom&amp;title=PHP-llibreria_OCI8"/>
	<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=PHP-llibreria_OCI8&amp;action=history"/>
	<updated>2026-08-30T11:55:48Z</updated>
	<subtitle>Historial de revisió per a aquesta pàgina del wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>http://wiki.joanillo.org/index.php?title=PHP-llibreria_OCI8&amp;diff=3258&amp;oldid=prev</id>
		<title>Joan a 10:52, 10 set 2009</title>
		<link rel="alternate" type="text/html" href="http://wiki.joanillo.org/index.php?title=PHP-llibreria_OCI8&amp;diff=3258&amp;oldid=prev"/>
		<updated>2009-09-10T10:52:05Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pàgina nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Segueixo aquest tutorial, que està molt ben explicat:&lt;br /&gt;
&lt;br /&gt;
http://www.acloudtree.com/?tag=php-php5-ubuntu-oci8-oracle-10g-9-8-710&lt;br /&gt;
&lt;br /&gt;
o bé &lt;br /&gt;
http://techxplorer.com/2008/09/22/installing-the-oci8-library-for-php-5-on-ubuntu-804-810/ (''Installing the oci8 library for PHP 5 on Ubuntu 8.04 / 8.10'')&lt;br /&gt;
&lt;br /&gt;
que són bàsicament el mateix&lt;br /&gt;
&lt;br /&gt;
==Instal.lar les dependències==&lt;br /&gt;
Treballo com a root&lt;br /&gt;
 $ sudo -i&lt;br /&gt;
Assegurar-se de què les següents dependències dels repositoris d'Ubuntu estan instal.lades.&lt;br /&gt;
&lt;br /&gt;
:1. build-essential - compilers and other tools necessary tools used to build software&lt;br /&gt;
:2. php5-dev - tools and other files necessary to build php modules&lt;br /&gt;
:3. php-pear - tools and other files necessary to download pear modules&lt;br /&gt;
:4. libaio1 - linux kernel aio access library&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Instal.lar el Oracle Instant Client==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Download the Basic and SDK zip files from the official Oracle [http://www.oracle.com/technology/software/tech/oci/instantclient/index.html website].&lt;br /&gt;
&lt;br /&gt;
Create the following directory to store the instant client files&lt;br /&gt;
      /opt/oracle/instantclient/&lt;br /&gt;
&lt;br /&gt;
Em descarrego els fitxers:&lt;br /&gt;
*oracle-instantclient-basic-10.2.0.4-1.i386.zip&lt;br /&gt;
*oracle-instantclient-devel-10.2.0.4-1.i386.zip&lt;br /&gt;
&lt;br /&gt;
Nota important: Download the appropriate Instant Client packages for your platform. All installations REQUIRE the Basic package.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 $ mkdir /opt/oracle&lt;br /&gt;
&lt;br /&gt;
move the .zip files in the “Documents” directory to the /opt/oracle directory&lt;br /&gt;
 $ mv /home/ubuntu/Documents/*.zip /opt/oracle&lt;br /&gt;
&lt;br /&gt;
Change to the /opt/oracle directory&lt;br /&gt;
 $ cd /opt/oracle&lt;br /&gt;
&lt;br /&gt;
Unzip the files&lt;br /&gt;
 $ unzip \*.zip&lt;br /&gt;
&lt;br /&gt;
rename instantclient directory&lt;br /&gt;
 $ mv instantclient_10_2 instantclient&lt;br /&gt;
&lt;br /&gt;
Change directory to instantclient, list the files&lt;br /&gt;
 $ cd instantclient&lt;br /&gt;
&lt;br /&gt;
Create symbolic links&lt;br /&gt;
 $ ln –s libclntsh.so.10.1 libclntsh.so&lt;br /&gt;
 $ ln –s libocci.so.10.1 libocci.so&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Create a source directory under /opt/oracle . This is where we will house the oci8 libraries.&lt;br /&gt;
 $ mkdir /opt/oracle/src&lt;br /&gt;
&lt;br /&gt;
Change the directory to /opt/oracle/src and download the oci8 tar using pecl&lt;br /&gt;
 $ cd /opt/oracle/src&lt;br /&gt;
 $ pecl download oci8&lt;br /&gt;
&lt;br /&gt;
Untar the oci8 libraries&lt;br /&gt;
 $ tar xvf oci8-1.3.4.tgz&lt;br /&gt;
&lt;br /&gt;
Change to the newly created oci8-1.2.4 directory and issue the following commands&lt;br /&gt;
 $ cd oci8-1.3.4&lt;br /&gt;
 $ phpize&lt;br /&gt;
&lt;br /&gt;
Set the ORACLE_HOME environment variable&lt;br /&gt;
 $ export ORACLE_HOME=/opt/oracle/instantclient&lt;br /&gt;
 $ echo $ORACLE_HOME&lt;br /&gt;
 /opt/oracle/instantclient&lt;br /&gt;
&lt;br /&gt;
Configure oci8 to install with the necessary parameters&lt;br /&gt;
 $ ./configure --with-oci8=share,instantclient,/opt/oracle/instantclient&lt;br /&gt;
&lt;br /&gt;
run make to compile&lt;br /&gt;
 $ make&lt;br /&gt;
&lt;br /&gt;
install oci8&lt;br /&gt;
 $ make install&lt;br /&gt;
&lt;br /&gt;
insert the extension=oci8.so into the php.ini and cli.ini files&lt;br /&gt;
 $ echo extension=oci8.so &amp;gt;&amp;gt; /etc/php5/apache2/php.ini&lt;br /&gt;
 $ echo extension=oci8.so &amp;gt;&amp;gt; /etc/php5/cli/php.ini&lt;br /&gt;
&lt;br /&gt;
restart apache&lt;br /&gt;
 $ /etc/init.d/apache2 restart&lt;br /&gt;
&lt;br /&gt;
create a phpinfo.php file in /var/www&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ joe /var/www/phpinfo.php&lt;br /&gt;
&amp;lt;?php phpinfo(); ?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now go to your browser and run the phpinfo file and look for the oci8 module&lt;br /&gt;
 http://localhost/phpinfo.php&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
OCI8 Support			enabled&lt;br /&gt;
Version 			1.3.4&lt;br /&gt;
Revision 			$Revision: 1.269.2.16.2.38.2.20 $&lt;br /&gt;
Active Persistent Connections 	0&lt;br /&gt;
Active Connections 		0&lt;br /&gt;
Oracle Instant Client Version 	10.2&lt;br /&gt;
Temporary Lob support 		enabled&lt;br /&gt;
Collections support 		enabled&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Directive			Local Value	Master Value&lt;br /&gt;
oci8.connection_class		no value	no value&lt;br /&gt;
oci8.default_prefetch		100		100&lt;br /&gt;
oci8.events			Off		Off&lt;br /&gt;
oci8.max_persistent		-1		-1&lt;br /&gt;
oci8.old_oci_close_semantics	Off		Off&lt;br /&gt;
oci8.persistent_timeout		-1		-1&lt;br /&gt;
oci8.ping_interval		60		60&lt;br /&gt;
oci8.privileged_connect		Off		Off&lt;br /&gt;
oci8.statement_cache_size	20		20&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Download my oratest php template file and configure it with the needed settings.&lt;br /&gt;
&lt;br /&gt;
Test the connection&lt;br /&gt;
 $ php /home/ubuntu/oratest.php&lt;br /&gt;
Connection Succesful&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?php&lt;br /&gt;
&lt;br /&gt;
//oracle connection variables&lt;br /&gt;
$ora_user = 	'YOUR_USERNAME';	//username&lt;br /&gt;
$ora_pass =	'YOUR_PASS';			//user password&lt;br /&gt;
$ora_host =	'SERVER_IP_OF_ORACLE&amp;quot;';		//host name or server ip address&lt;br /&gt;
$ora_db   = 	'YOUR_DATABASE';	//database name&lt;br /&gt;
&lt;br /&gt;
// place variable into oci_connect function, then place funtion in variable&lt;br /&gt;
$ora_conn = oci_connect($ora_user,$ora_pass,'//'.$ora_host.'/'.$ora_db);&lt;br /&gt;
&lt;br /&gt;
// error handling&lt;br /&gt;
	if (!ora_conn){							// if variable $ora_conn fails to connect&lt;br /&gt;
		// do the following if it fails&lt;br /&gt;
		$ora_conn_erno = oci_error(); 			// insert oci_error() function into variable&lt;br /&gt;
		echo ($ora_conn_erno['message'].&amp;quot;\n&amp;quot;); 	// print the $ora_conn_erno variable/oci_error() function selecting only the message (human readable)&lt;br /&gt;
		oci_close($ora_conn); 					// close the connection just in case php doesn't close it&lt;br /&gt;
	} else {&lt;br /&gt;
		// if it doesn't fail it will proceed with the rest of the script&lt;br /&gt;
		echo &amp;quot;Connection Succesful\n&amp;quot;; 	//echo message if connection does not error&lt;br /&gt;
		oci_close($ora_conn); 			// close the connection&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ara ja podem començar a fer coses més interessants:&lt;br /&gt;
&lt;br /&gt;
funcions de la llibreria OCI8: http://es2.php.net/manual/es&lt;br /&gt;
&lt;br /&gt;
Està ben instal.lada la llibreria, però em dóna un warning&lt;br /&gt;
&lt;br /&gt;
==Notes:== &lt;br /&gt;
*si no em funciona el tnsping, és perque no estan ficades les variables d'entorn. El script del SQL*Plus inicialitza les variables d'entorn&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Message 3511 not found; No message file for product=network, facility=TNSTNS-03505: Message 3505 not found; No message file for product=network, facility=TNS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*he tingut bastants problemes perquè he seguit un manual en què per fer oci_connect la sintaxi era:&lt;br /&gt;
:$c1 = oci_connect(&amp;quot;joan&amp;quot;, &amp;quot;bbdd&amp;quot;, &amp;quot;XE&amp;quot;)&lt;br /&gt;
El que funciona realment és&lt;br /&gt;
:$c1 = oci_connect(&amp;quot;joan&amp;quot;, &amp;quot;bbdd&amp;quot;, &amp;quot;//oracle/XE&amp;quot;)&lt;br /&gt;
on ''oracle'' és el nom de la màquina o la IP. L'error que tenia era:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Warning:  oci_connect() [function.oci-connect]: ORA-12154: TNS:could not resolve the connect identifier specified in /usr/share/oracle-php/prova1.php on line 8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Instal.lació setembre 2009 sobre Oracle 11g==&lt;br /&gt;
Seguint aquestes instruccions ha funcionat perfectament. Se m'instal.la la versió OCI 1.3.5.&lt;br /&gt;
&lt;br /&gt;
Compte! perquè en el procés d'instal.lació faig &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ export ORACLE_HOME=/opt/oracle/instantclient&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
però aquest no és el ORACLE_HOME de la meva instal.lació:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
root@ubuntu-bbdd:/opt/oracle/src/oci8-1.3.5# export ORACLE_SID=BBDD&lt;br /&gt;
root@ubuntu-bbdd:/opt/oracle/src/oci8-1.3.5# . oraenv&lt;br /&gt;
ORACLE_SID = [BBDD] ? &lt;br /&gt;
The Oracle base for ORACLE_HOME=/u01/app/oracle/product/11.1.0/bbdd is /u01/app/oracle&lt;br /&gt;
root@ubuntu-bbdd:/opt/oracle/src/oci8-1.3.5# echo $ORACLE_HOME &lt;br /&gt;
/u01/app/oracle/product/11.1.0/bbdd&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Autor}}, febrer 2009&lt;br /&gt;
[[Categoria: Oracle]]&lt;br /&gt;
[[Categoria: PHP]]&lt;/div&gt;</summary>
		<author><name>Joan</name></author>
		
	</entry>
</feed>