WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : PHP CLASS for ORACLE (database connectivity)
Categories : PHP, PHP Classes, Classes and Objects, Databases, Oracle
Suraj Thapaliya
Date : Mar 08th 2007
Grade : 3 of 5 (graded 2 times)
Viewed : 15031
File : 4597.zip
Images : No Images for this code example.
Search : More code by Suraj Thapaliya
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
Like this code?
Show the author your appreciation.
 

This is the database connectivity script of PHP and ORACLE all the functional work are in the single file such as query,fetch, generate ID etc so everyone who really wants or working in php + oracle may get more help from it

Please see attached file above.


class.db.php
<?php
class db_connect{
      var
$sid, $connection;
      var
$query;
      var
$host;
      var
$total_record,$rec_position;
      var
$total_fields, $field_name;
     
/*This function connect to the database . This function is called
      whenever object is created. */

       
function db_connect(){
               
$this->host="".ORCL_HOST."";
               
$this->sid="(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=".ORCL_HOST.")(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=".ORCL_SERVICE_NAME.")))";
               
$this->connection = ocilogon(ORCL_USER_NAME,ORCL_PASSWORD,$this->sid) or die ($this->get_error_msg($this->connection,"Problem while connecting to ".$this->sid." server..."));//username,password,sid
           
}


       
/*This function query at database */
       
function db_query($query_str="")
       {
           
$this->sql=$query_str;
           
$this->rec_position=0;
         
// if($query_str==""){
           //   $query_str=$this->query_stmt;
           //}
           
$this->query = @ociparse($this->connection, $query_str);
           
ociexecute($this->query)or die($this->get_error_msg($this->query ,"Query Error : ".$query_str));
       }

       
/*This function query at database which returns TRUE if SUCCESSFUL and FALSE if UNSUCCESSFUL */
       
function db_query_return($query_str="",$db=""){
           if(
$query_str==""){
             
$query_str=$this->query_stmt;
           }
           
$this->query = ociparse($this->connection, $query_str);
            if(
$db=="Default") {
                   return
ociexecute($this->query,OCI_DEFAULT);
           } else {
                   return
ociexecute($this->query);
           }
       }

    function
selectBox($sql='',$selected='',$name='select',$multiple='',$size='',$parameter=NULL)
    {
       
$this->db_query($sql);
       
$output="<select name='$name' $multiple $size $parameter>";
       
$output.="<option value=''>--Select--</option>";
        while(
$result=$this->db_fetch_array())
        {
            if(
$result[0]==trim($selected)) {
               
$a="selected";   
            } else {
               
$a="";
            }
           
$output.="<option value=".$result[0]." $a>".$result[1]."</option>";
        }
       
$output.="</select>";
        echo
$output;
        unset(
$output);
    }
   
    function
db_fetch_val()
    {
       
$result=$this->db_fetch_array(0);
        return
$result[0];
    }

    function
gen_id($table_name='',$field='',$increment='') {
         if(empty(
$increment)) {
             
$increment=1;
         } else {
             
$increment=$increment;
         }
       
$sql="select nvl(max($field),0) + $increment from $table_name";
       
$this->db_query($sql);
        return
$this->db_fetch_val();
    }
     
       function
db_fetch_array($fetch_type=0,$db="DEFAULT"){
       
$result=@oci_fetch_array($this->query,OCI_BOTH+OCI_RETURN_NULLS);
       
           if(!
is_array($result))
              return
false;
             
$this->total_field=OCINumCols($this->query);
                     if(
$db=="DEFAULT"){
                           foreach(
$result as $key=>$val){
                                   
$result[$key]=trim($val);
                                   
$result[$key]=trim(htmlspecialchars($val));
                           }
                     }
           return
$result;
       }



       function
get_field_name($i){
           return
OCIColumnName($this->query, $i+1);
       }


       function
get_num_fields() {
           return @
ocinumcols($this->query);
       }

       function
get_field_type($i, $sql=""){
               return
ocicolumntype($this->query, $i+1);
       }
       
       function
get_field_size($i, $sql=""){
               return
ocicolumnsize($this->query, $i+1);
       }
       

       function
total_record(){
          return
oci_num_rows($this->query);
       }


       function
free(){
         
ocifreestatement($this->query);
         
ocilogoff($this->connection);
          unset(
$this);
       }


       function
db_fetch_tr ($css="",$colname='y',$add='y',$update='y',$delete='y'){
          if(
$css!=""){
             
$css_val="class=".$css;
          }
          if(!empty(
$colname)) {
              echo
"<tr $css_val>";
              for (
$i=0; $i< $this->get_num_fields(); $i++) {
                   echo
"<td>".$this->get_field_name($i)."<td>";
              }
             
//echo "<td>Update<td>Delete";
             
echo "</tr>";
          }
          while(
$result=$this->db_fetch_array(1)){
                    echo
"<tr $css_val>";
                           for (
$j=0; $j<$this->get_num_fields(); $j++) {
                               
$cname=$this->get_field_name($j);
                                   echo
"<td>".$result[$cname]." <td>";
                           }
                    echo
"</tr>";
          }

       }


       function
get_error_msg($error_no,$msg=""){
         
$log_msg=NULL;
         
$error_msg="<b>Custom Error :</b> <pre><font color=red>\n\t".ereg_replace(",",",\n\t",$msg)."</font></pre>";
         
$error_msg.="<b><i>System generated Error :</i></b>";
         
$error_msg.="<font color=red><pre>";
                foreach(
ocierror($error_no) as $key=>$val){
                       
$log_msg.="$key :  ".$val."\n";
                       
$error_msg.="$key : $val \n";
                }

               
$error_msg.="</pre></font>";
                return
$error_msg;
       }

       function
get_error_msg_array($error_no){
          return
ocierror($error_no);
       }
}
?>



Online Automatic Class Generator for MySQL Tables
Categories : PHP, PHP Classes, Classes and Objects, Databases, MySQL
Simple class for accessing databases like MSSql Server, Oracle etc by Raju
Categories : PHP, MS SQL Server, Databases, PHP Classes, Oracle
Mssql database Manager
Categories : PHP, Databases, MS SQL Server, Classes and Objects, PHP Classes
MySQL Handler
Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes
TableMaint: class to help in the updating of data stored in database tables
Categories : PHP, PHP Classes, Databases
PHP5 SQLite Abstraction class
Categories : PHP, PHP Classes, SQLite, Databases
Simple usersOnline class - keep track of how many users are online on your site
Categories : PHP, PHP Classes, Databases, MySQL
PostGreSQL and MySQL 2 in 1 db Manager
Categories : PHP, PHP Classes, Databases, PostgreSQL, MySQL
Connecting to Oracle with php3
Categories : Oracle, PHP, Databases
This is a class with functions that are taken from simple SQL statements. I made it to have an easier connection between PHP3 and DBase files.
Categories : General SQL, PHP, PHP Classes, Databases
PHP Object Example of the Perl DBI with MySQL
Categories : PHP, PHP Classes, MySQL, Databases, Perl
A database abstraction layer for the PHP Oracle 8 module (available from PHP 3.0.5). It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, Oracle, PHP, Arrays, Variables
Password reminder
Categories : PHP, PHP Classes, Databases, MySQL, Mail
Simple class to create insert and update statements. Independent of the access to the database. Makes handling complex inserts easier - especially when the table structure is liable to change.
Categories : Databases, PHP Classes, PHP
The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view.
Categories : PHP, PHP Classes, Java Script, AJAX, Databases