As a follow up to "connect PHP and MySQL using JNDI & PHP-Java Bridge"
Thanks Dan,
I understand what you are saying. I have been thinking about trying that method too.
I made some progress with the JDBC/PHP using this code:
<?php
require_once ("java/Java.inc");
$drivermanager = new JavaClass('java.sql.DriverManager');
$conn1 = $drivermanager->getConnection("jdbc:mysql://localhost:3306/javatest?user=javauser&password=javadude") or die("Unable to connect to MySQL");
print $conn1;
echo '<br /><br />';
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'}."<br>";
}
mysql_close($conn1);
?>
This code returns "com.mysql.jdbc.JDBC4Connection@17351735
Could not connect: "
However if I remove $conn1 from this line:
mysql_select_db("javatest", $conn1) or die('Could not connect: ' . mysql_error());
to get this line:
mysql_select_db("javatest") or die('Could not connect: ' . mysql_error());
I get the error:
com.mysql.jdbc.JDBC4Connection@4bd04bd0
Could not connect: Access denied for user 'root'@'localhost' (using password: NO)
I think this indicates that the problem is with the mysql_select_db() function. I don't know whether I've coded this correctly seeing as I am suing JDBC. Maybe someone knows?
Anyway, going down the Java route may be difficult as I know nothing about Java really.
Anyway, if I do ahead and write the Java code, would I compile it as a *.jar file? Or would I compile it as a *.class file and use it as a servlet??
I'm guessing as a *.jar file so then the data within it can be called in PHP?
I'm still wondering though, would the SQL queries have to be coded in Java? Or could they be coded in PHP once the connection is established - the only reason I ask is because i am kind of up to that point already with my code above....I have a connection but the database cannot be selected?
rgs J
This message has been scanned for viruses by MailControl - www.mailcontrol.com
|