Skip to content

Service and library to allow a PHP application to interface with a database via JDBC

License

Notifications You must be signed in to change notification settings

JCotton1123/php-jdbc-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP-JDBC Bridge

The PHP-JDBC bridge is a service and library for allowing a PHP application to interface with a database for which only a JDBC driver exists. This is a fork of PJBS.

The java component runs as a service which accepts socket requests from the PHP component allowing the transfer of request and response between PHP and the JDBC database.

Requirements

  • Java 1.6+
  • PHP 5.3+
  • A JDBC driver

Build (Java Service)

To build the PHP-JDBC bridge jar:

cd java
./build.sh

To build a PHP-JDBC RPM:

cd java
./build.sh
./build-rpm.sh

Usage

Java Service

To run the service:

java -cp 'lib/pjbridge.jar:lib/commons-daemon-1.0.15.jar:lib/<JDBC driver>.jar Server <JDBC driver entry point> <port>

Example:

cd java
java -cp 'lib/pjbridge.jar:lib/commons-daemon-1.0.15.jar:lib/dharma.jar' Server dharma.jdbc.DharmaDriver 4444

where the lib directory contains the php-jdbc jar, the commons-daemon jar and your JDBC driver jar.

PHP

Example:

<?php
require "PJBridge.php";

$dbHost = "server";
$dbName = "";
$dbPort = "1990";
$dbUser = "dharma";
$dbPass = "";

$connStr = "jdbc:dharma:T:${dbHost}:${dbName}:${dbPort}";

$db = new PJBridge();
$result = $db->connect($connStr, $dbUser, $dbPass);
if(!$result){
    die("Failed to connect");
}

$cursor = $db->exec("SELECT * FROM \"AR Customer File\"");

while($row = $db->fetch_array($cursor)){
    print_r($row);
}

$db->free_result($cursor);