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

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



Hi
 
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 :
 
[code]
 
class DB {

 function DB(){

  $this->values = array();  

 }//DB

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

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

    function execute($sql_query) {     
  
        if(!$this->conn_id){

            $this->connect();

        }//if
       
        preg_match_all("/\:[A-Za-z|0-9|_]{1,}\:/",$sql_query,$matches);
       
        $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);
        }//while
          
  reset($this->values);
  
        $this->sql_result = mysql_query($sql_query,$this->conn_id);

        if(!$this->sql_result && !hs_ereg("^LOCK TABLES",$sql_query) && $sql_query!="UNLOCK TABLES"){         
         die($sql_query.":".mysql_error($this->conn_id));
        }//if
       
        return $this->sql_result;

    }//execute

    function insert($sql_query){

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

            $this->execute($sql_query);

        }//if

        $this->clean();
        return mysql_insert_id($this->conn_id);       

    }//insert
   
    function update($sql_query){

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

            $this->execute($sql_query);

        }//if

        $this->clean();
        return mysql_affected_rows($this->conn_id);       

    }//update

    function fetch($sql_query){

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

            $this->execute($sql_query);

        }//if

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

    }//fetch

    function row($sql_query){

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

            $this->execute($sql_query);

        }//if

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

    }//row

    function result($sql_query){

     $ret_array = array();    

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

        }//while
        
        @mysql_free_result($this->res);      
        $this->clean();
        return $ret_array;

    }//result

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

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

}//DB class

$DB = new DB;
 
[/code]
 
 
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,
Amir

[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