PHP-Java Bridge: Connect PHP to MySQL using JNDI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi everyone!

This is driving me nuts!

I have setup a Linux webserver. Tomcat is running at the backend and is
connected to Apache at the frontend using mod_proxy. At the moment I have a
few test applications setup, which involves Apache sending JSP requests to
Tomcat via mod_proxy. They all work fine.

I also have some JSP code that uses a JNDI connection to the MySQL database
using MySQL Connector / J. All the configuration is done in Tomcat in the
XML files. This works fine too.

Now what I want to do is use PHP code to connect to MySQL using JNDI,
instead of using JSP code. This is where the sourceforge open-source
PHP-Java Bridge comes into it.

The php-java bridge is deployed in Tomcat's webapps folder (it came as a
*.war file). This is all thats necessary for it to work according to their
tech support.

Is there anyone around that knows how to code this using PHP?

I had a go at this, and my (most-likely awful) attempt is here:

<?php
require_once("java/Java.inc");
require_once("java/JavaBridge.inc");

try {
$dbh = new PDO("java:comp/env/jdbc/TestDB");
foreach ($dbh->query('SELECT * from testdata') as $row) {
  echo "<pre>";  
  print_r($row);
  echo "</pre>";
}
$dbh = null;
} catch (PDOException $e) {
  print "Error!: " . $e->getMessage() . "<br/>";
  die();
}
?>

Now I don't think that PDO will support what I have done, and that is to try
and call the JNDI connection. I get the error message "Error!: could not
find driver"

Another attempt was to use the following code:

<?php
require_once("java/Java.inc");
require_once("java/JavaBridge.inc");

$conn = mysql_connect("java:comp/env/jdbc/TestDB");
print $conn;
?>

But this gave the error:

Warning - mysql_connect() [ function.mysql-connect function.mysql-connect ]:
Unknown MySQL server host 'java' (1)

I guess this post could have gone in the Java forum too, but I thought it
was more of a PHP issue?

Any help would be great. 

rgs J
-- 
View this message in context: http://www.nabble.com/PHP-Java-Bridge%3A-Connect-PHP-to-MySQL-using-JNDI-tp21562460p21562460.html
Sent from the PHP - General mailing list archive at Nabble.com.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux