Re: PgSQL and integration between 2 PHP programs and a Java program

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

First tI should thank Brew and Juan for their kind help.
Second it seems that the php applications doesn't use ADODB as here's a sample DB connection function of one of the PHP sctipts :
class DB {

 function DB(){

  $this->values = array();  


    function connect() {
        $this->conn_id = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS,1);
        $version = $this->version();
        if($version >= 4.1){
         $encoding = extract_encoding("mysql");
          $sql_query = "SET NAMES '".$encoding."'";

    function disconnect(){
    function version(){
     $sql_query = "SELECT VERSION()";
     $version   = $this->single($sql_query);
     $version   = ereg_replace("[^0-9|\.]","",$version);
     return $version;

    function execute($sql_query) {     


        $patterns = $matches[0];
        while(list(,$val) = each($patterns)){
         $key   = substr($val,1,strlen($val)-2);
         $value = stripslashes($this->values[$key]);
         $sql_query = hs_ereg_replace($val,mysql_escape_string($value),$sql_query);
        $this->sql_result = mysql_query($sql_query,$this->conn_id);

        if(!$this->sql_result && !hs_ereg("^LOCK TABLES",$sql_query) && $sql_query!="UNLOCK TABLES"){         
        return $this->sql_result;


    function insert($sql_query){

     if((!$this->sql_result)||($sql_query != $this->sql_query)){



        return mysql_insert_id($this->conn_id);       

    function update($sql_query){

     if((!$this->sql_result)||($sql_query != $this->sql_query)){



        return mysql_affected_rows($this->conn_id);       


    function fetch($sql_query){

        if((!$this->sql_result)||($sql_query != $this->sql_query)){



        $this->sql_query = $sql_query;
        $result = @mysql_fetch_object($this->sql_result);
        return $result;


    function row($sql_query){

        if((!$this->sql_result)||($sql_query != $this->sql_query)){



        $this->sql_query = $sql_query;
        $result = @mysql_fetch_assoc($this->sql_result);
        return $result;


    function result($sql_query){

     $ret_array = array();    

        while($this->res = $this->row($sql_query)){
            $ret_array[] = $this->res;

        return $ret_array;


    function single($sql_query){
        return @mysql_result($this->sql_result,0);

    function lock($table){
     $sql_query="LOCK TABLES `".$table."` WRITE";
    function unlock(){
     $sql_query="UNLOCK TABLES";
    function clean(){
     $this->sql_query = "";

}//DB class

$DB = new DB;
Well, this way I think I would need very much modification in source codes to make the PHP scripts talk to a PgSQL server :(
After all I have thought of 3 methods of integration. I would like everyone who have an experience to share it with me and vote for the best methd that comes to your mind :
1. change the PHP programs somehow that the registration and password modification ( and maybe profile editing ) won't be accessed. This way I will write a centralized registeration and editing script where users can register and update their profile. When a user is registered or updated all the new information including username, password, name, last_name, address an etc will be updated in all connected databased + LDAP server. This way for example user "sample" with pass "sample" will be stored in almost 10 databases + LDAP server. Then each application will read from its own database ( MySQL, PgSQL or LDAP ) and authenticates the user. Also CAS can be integrated using LDAP as the main directory service and phpCAS or JavaCas as the client ticketing system.
Pros : no change in any PHP or Java applications, but just integration of CAS for authentication. Centeral user managemet like what Yahoo offers ( Account Setting in Yahoo ). Seprate databased for each application that maybe increases security.
Cons : Huge amount of data duplication as each username. password, address and other related fields will be the same in many databases! , High database loads due to multiple UPDATE of several tables in different DBs.
2. Change all the applications to use PgSQL and share the same database.
Pros : No data duplication, fast database access ( no high loads like method no.1 )
Cons : Heavy source code editing
3. Change all the applications to use LDAP.
Pros : No data duplication, fast database access ( no high loads like method no.1 )
Cons : Heavy source code editing, I'm not sure if LDAP can handle this much insert & update queries as it's mostly a directory service and is not usefull to be used as a dabatase for other informations like profiles and etc.

Warm Regards,

[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux