SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am using the db_mysql class from phplib but i want the servername, password etc variables to be in a different file that has already been included (or could be included from inside db_mysql.

    How do i do this? using global did not work

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2000
    Posts
    1,483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try putting this in the class:
    PHP Code:
    var $username $username;
    var 
    $password $password
    etc.

    Or you could declare the variables with var $variable as blank, then fill them in when you initiate the class in a script like this:
    PHP Code:
    $class->username $username;
    $class->password $password

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tried both of these, am complety stuck.

    This is for example my top of the class:

    PHP Code:
    class DB_Sql {

      
    /* public: connection parameters */
      
    var $host "localhost";
      var 
    $database "";
      var 
    $user "root";
      var 
    $password ""
    and this is my include type file:

    PHP Code:
    $db = new DB_Sql;
    $dbname="deskpro";
    $db->user=$user;
    $db->password=$password;
    $db->host=$host;
    $db->dbname=$dbame

    if i run the 2nd file, i always get the error

    Code:
    Database error: cannot use database 
    MySQL Error: 1046 (No Database Selected)
    Session halted.
    whatever happens. The name is not getting into the class.


    doing var $username = $username; gave a syntax errror. The 2nd way is the way vb does it but i can't get it to work! any idea what i am doing wrong?

  4. #4
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    problem solved, don't worry


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •