Jump to content

russellharrower

Member
  • Posts

    11
  • Joined

  • Last visited

Posts posted by russellharrower

  1. I am getting an error, and i am unsure what i have done wrong.

    LIVE demo - http://www.designvisa.com/beta/include/dbconnect/opendb.php

     

    $vconfig = new VConfig();
    
       //Create objects from DBObject class.
       $myObj = new DBConnect("localhost","$vconfig->user","$vconfig->dbpass","$vconfig->db");
    
       //Call methods of objects.
       $myObj ->connectToMySQL();
    
       $myObj2 = new DBData();
       $myObj2 ->selectDB();
       $myObj2 ->showMessage();
    
    class  DBConnect{
           /////////////////////////////////////////////////
           // PRIVATE PROPERTIES  
           /////////////////////////////////////////////////
           private $hostname, $username, $password, $db_name, $con;
    
       /**
          * Constructor
          * @param String $hostname,$username,$password,$db_name. 
          * All information we need to provide whenever connect to db.
          */
           public function __construct($hostname,$username,$password,$db_name){
               $this->hostname = $hostname;
               $this->username = $username;
               $this->password = $password;
               $this->db_name = $db_name;
           }
    
       /**
          * Connect to MySQL.
          * @return void
          */
           public function connectToMySQL(){
               $this->con = mysql_connect($this->hostname,$this->username,$this->password);
               if($this->con){
                   echo "
    Connected sucessfully to MySQL .
    ";
               }
               else{
                   die( "
    Could not connect to MySQL" . mysql_error() . ".
    ");
               }
           }
    
    
     }      
    
    
    
    class DBData extends DBConnect{
    
    public function selectDB(){
               $result = mysql_select_db($this->db_name,$this->con);
               if($result){
                   echo "
    Connected sucessfully to database ' ".$this->db_name." ' .
    ";
               }
               else{
                   die( "
    Could not connect to database ' ". $this->db_name. " '  ".mysql_error() . ".
    ");
               }
           }
    }
    
    
    
    
    class DBClose extends DBConnect{
       function closeConnection(){
          //Do something else here and at the end you can
          mysql_close();//For example
       }
    }
    

     

    Can anyone help!

  2. Just another question, and an objectName a class name? $DBConnect.closeConnection();

     

    Would something like this work?

     

    class  DBConnect{
           /////////////////////////////////////////////////
           // PRIVATE PROPERTIES  
           /////////////////////////////////////////////////
           private $hostname, $username, $password, $db_name, $con;
    
       /**
          * Constructor
          * @param String $hostname,$username,$password,$db_name. 
          * All information we need to provide whenever connect to db.
          */
           public function __construct($hostname,$username,$password,$db_name){
               $this->hostname = $hostname;
               $this->username = $username;
               $this->password = $password;
               $this->db_name = $db_name;
           }
    
       /**
          * Connect to MySQL.
          * @return void
          */
           public function connectToMySQL(){
               $this->con = mysql_connect($this->hostname,$this->username,$this->password);
               if($this->con){
                   echo "
    Connected sucessfully to MySQL .
    ";
               }
               else{
                   die( "
    Could not connect to MySQL" . mysql_error() . ".
    ");
               }
           }
    
    
     }      
    
    
    
    
    
    class dbclose extends DBConnect{
       function closeConnection(){
          //Do something else here and at the end you can
          mysql_close();//For example
       }
    }
    

  3. Thanks Quyen, Just wondering the following:

     

    Say i want to have one file that handles connecting to the database. - opendb.php

    and one that closes the database - closedb.php

     

    is that possible, and how?

     

    Then say i want another a page to handle MYSQL. - fruitdb.php

    How would one go about that?

  4. hi Quyen,

     

    I get what you are doing, but just one last question if you can help that would be great.

    how to i fetch data from the database using oops?

     

    like say i need to show the table called "yum"

     

    inside the table "yum" it has two rows with data, under the row called "fruit"

    1 - apple

    2 - banana

     

    But i when i run the select fruit from yum;

    it prints both of the fruit - "applebanana"

    what i need it to do is give each fruit a class or a way i can call it by

     

    $class->fruitone;

    $class->fruittwo;

     

    Can you help there?

  5. Hi guys, I have looked everywhere with NO success, I don't understand any of these frameworks that are already out,

    and i have read all the killerphp.com documents and watch all the videos that i can find about OOP and still cant find what i need.

     

    I am new to OOP but know PHP, if someone can PLEASE help me out, and show me an example on how to use OOP to connect to MySQL that would be GREAT!

     

    PLEASE HELP

     

    Thanks

  6. Hi,

     

    I think Stefan's right, After you read some more about Model - Control - View, You may understand what does he mean by that.

     

    For now I have some comment for you like these:

     

    for Q2:

    Acctually I don't think there are any rule to say that your class has to be this long or that long. Number of fields and methods in a class, it depends on your object you are creating.

     

    for Q3:

    You should read some more about OOP. if you understand OOP then you might have something to do with this object (the object i mentioned here is about the object in your question Q3). How to organize your php files??? (0_0). Let's think about your question.

    You can have different classes in a file. thats ok. Lets think your php file (You have different classes in this file) look like a library php file wherever you want to create an object, you can include that library file in and create your object.

    You also create different library php files depend on how you want to organize your projects.

     

    Thats all I can say now. Hope it can help you.

    Sorry my english is pretty bad, then still hope that you can understand what i mean.

     

    Quyen,

     

     

    Sorry?? i am not understanding what you are talking about...

  7. why not just have one row for keywords and separate each keyword with a , if you look into a cms database like wordpress, joomla etc. you will see this is how they do it (off the top of my head)

     

    I know this is how i did it for a client.

  8. Oh also i forgot to let you know, it can also play videos, something your church may want to do later down the road.

     

    There is a wizard that will show you how to get the player to work on your site including the html code.

     

    Also it works on all computers and in all browsers because it is flash.

  9. Can i suggest that you use something like JW flash player, its a free Flash player, that will allow users to click play and it will play the mp3 or any file that you want.

     

    You can however also make it fetch the audio file from a mysql database, or any database, this way you dont have to make a xml file, or even a page for each audio file.

  10. Hi, i like your script, i have been having issues connecting with the DB using OOPS however i seem to get a blank page when i use your script.

     

    I understand why i am getting a blank page, due to i have not called the class, but when i try to call the class i can't.

     

    I was wondering if you would kindly show us, how you would call the viewResult...

     

    Thanks

    Russell H.

×
×
  • Create New...