Encapscms 0.3.6 > Core / DB Sql.php

Questions? Need Help? Want to share? » PHP Forum
Script Name:
Encapscms 0.3.6

Download:
encapscms-0.3.6.zip

Category:
Content Management

Archive Content:

Encapscms 0.3.6 > Admin

Encapscms 0.3.6 > Admin > Html

Encapscms 0.3.6 > Admin

Encapscms 0.3.6 > Admin > Sql

Encapscms 0.3.6

Encapscms 0.3.6 > Core

Encapscms 0.3.6

Encapscms 0.3.6 > Html

Encapscms 0.3.6 > Html > Expo

Encapscms 0.3.6 > Html > Expo > Images

Encapscms 0.3.6 > Html > Expo > Images > Gallery

Encapscms 0.3.6 > Html > Expo > Images

Encapscms 0.3.6 > Html > Expo > Images > Temp

Encapscms 0.3.6 > Html > Expo > Images

Encapscms 0.3.6 > Html > Expo

Encapscms 0.3.6 > Html > Light

Encapscms 0.3.6 > Html > Raym

Encapscms 0.3.6 > Html > Raym > Equipment Files

Encapscms 0.3.6 > Html > Raym > Equipment Files > Temp

Encapscms 0.3.6 > Html > Raym

Encapscms 0.3.6 > Html > Raym > Img

Encapscms 0.3.6 > Html > Raym

Encapscms 0.3.6 > Img

Encapscms 0.3.6

Encapscms 0.3.6 > Sql

Encapscms 0.3.6

DB Sql.php:


<?php
//modified 29 jan 2005

class DB_sql{
    
    function 
DB_sql($host, $user, $pass, $db, $type, $debug=false){
        
//$this->config = $config;
        
$this->host $host;
        
$this->user $user;
        
$this->password $pass;
        
$this->db $db;
        
$this->debug $debug;
        
$this->db_type $type;

    }

    function 
exec($query){
        if(
$this->debug)echo "<br>".$query;
        switch (
$this->db_type){
            case 
"mysql":return $this->mysql_exec($query);break;
            case 
"pgsql":return $this->pg_exec($query);break;
        }
    }    
    
    function 
select($query){
        
$returned = array();
        
$result $this->exec($query) or print("<br><b>Error:</b> unable to execute query $query");
        switch (
$this->db_type){
            case 
"mysql":while($line mysql_fetch_array($result))$returned[] = $line;break;
            case 
"pgsql":while($line pg_fetch_array($result))$returned[] = $line;break;
        }
        return 
$returned;
    }

    
//------------------------------------------
    
function mysql_exec($query){
        
$link=mysql_connect($this->host, $this->user, $this->password) or die("<br><b>Error:</b> unable to connect db server"mysql_error());
        
mysql_select_db("$this->db"
            or print(
"<br><b>Error:</b> unable to select db $this->db"mysql_error());
        
$result=mysql_query($query
            or print(
"<br><b>Error:</b> unable to execute query: [$query]"mysql_error());
        return 
$result;
    }

    function 
pg_exec($query){            
        
$link=pg_connect("host=$this->host user=$this->user password=$this->password dbname=$this->db"
            or print(
"<br><b>Error:</b> unable to connect db server");
        
$result=pg_query($query
            or print(
"<br><b>Error:</b> unable to execute query $query");
        return 
$result;
    }    
    
    function 
mysql_select($query){
        
$returned = array();
        
$result $this->exec($query) or print("<br><b>Error:</b> unable to execute query $query");
        while(
$line mysql_fetch_array($result))
            
$returned[] = $line;    
        return 
$returned;
    }

    function 
pg_select($query){
        
$result $this->exec($query);
        while(
$line pg_fetch_array($result))
            
$returned[] = $line;    
        return 
$returned;
    }
    
    function 
usedump($_file){
        
$fp fopen($_file, 'r');
        
$query '';
        while (
$line=fgets($fp, 1024)){
            
//echo '<br>SOURCE:'.($line);
            
if( (substr($line, 0, 2) == '  ' && $query == '')
                || 
substr($line, 0, 2) == '--' 
                
|| substr($line, 0, 1) == '#'
                
){
                }else{
                    
$query .= $line;
                }
            
            if(
strstr($line, ';')){
                
$query trim($query);
                
//echo '<br>['.$query.']<br>';
                
$this->exec("$query");
                
/*$fp_ = fopen($_file.'_out', 'a');
                fputs($fp_, "\n".$query);
                fclose($fp_);*/
                
$query '';
            }
        }
        
fclose($fp);
    }
    
    function 
test($table, $field, $value){
        
//echo '<hr>test($table, $field, $value):'."test($table, $field, $value)";
        
$sql "SELECT $field FROM $table";
        
$result $this->select($sql);
        return (
$result[0][0] == $value)?true:false;
    }    
}
?>



Other Content Management Scripts:

WebMaster Resources Home

©RingsWorld.com