Re: [PHP] PHP-Java Bridge: Connect PHP to MySQL using JNDI

2009-01-20 Thread jpmad4it

Thanks.

However, I'm using this process as a test. In the proper application we will
be using a JDBC or JDNI connection initiated by PHP to connect to our IDMS
database. Its complicated but it means we have to use the PHP-Java Bridge,
Java and JDBC. so we can't use ODBC.

I'm using this as a test to get my head around the code. I've resorted to
try and get it working with the JDBC connection coded in the script for now,
and i'll move on to JNDI later. I have now got this code:

getConnection("jdbc:mysql://localhost:3306/javatest?user=javauser&password=javadude")
or die("Unable to connect to MySQL");

print $conn1;
echo '';

mysql_select_db("javatest", $conn1) or die('Could not connect: ' .
mysql_error());

$result = mysql_query("SELECT id, foo, bar FROM testdata");
while ($row = mysql_fetch_array($result)) {
print "ID:".$row{'id'}." Name:".$row{'foo'}." 
".$row{'bar'}."";
}
mysql_close($conn1);

?>

This gives the following reply:

com.mysql.jdbc.jdbc4connect...@22622262

Could not connect: 

It seems to connect Ok, but I think it gets stuck at the mysql_select_db()
function because no database information is being extracted.

I've tested a few things, and if I remove the $conn1 from this line:

mysql_select_db("javatest", $conn1) or die('Could not connect: ' .
mysql_error());

to give this:

mysql_select_db("javatest") or die('Could not connect: ' . mysql_error());

I get the following error:

com.mysql.jdbc.jdbc4connect...@22862286

Could not connect: Access denied for user 'root'@'localhost' (using
password: NO)

So I 'think' this indicates that the first lot of code connects OK - it just
can't access the database. Maybe I'm using the wrong code to select the
database??:

mysql_select_db("javatest", $conn1) ;

Can anyone see why my mysql_select_db() function is not working? Maybe its
not possible to use this with the way that I have used the
drivermanager->getConnection method?

Please help :-((
-- 
View this message in context: 
http://www.nabble.com/PHP-Java-Bridge%3A-Connect-PHP-to-MySQL-using-JNDI-tp21562460p21565513.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



Re: [PHP] PHP-Java Bridge: Connect PHP to MySQL using JNDI

2009-01-20 Thread ceo

In general, if you are trying to get DB connections to work in a hybrid 
situation, and no native driver is behaving, try ODBC.



It's crude, slow, and not pretty, but it should work.



You can set it up so that you can go back later and dink around with drivers 
and re-compiling, but at least have a known working solution in the meantime.



I don't do Java, so that's just general advice...



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



[PHP] PHP-Java Bridge: Connect PHP to MySQL using JNDI

2009-01-20 Thread jpmad4it

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:

query('SELECT * from testdata') as $row) {
  echo "";  
  print_r($row);
  echo "";
}
$dbh = null;
} catch (PDOException $e) {
  print "Error!: " . $e->getMessage() . "";
  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:



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