[thelist] guidance for a rooky on a database class in PHP

jsWalter jsWalter at torres.ws
Thu Jul 3 10:33:57 CDT 2003

I "borrowed" the database class definition (see below) from the PHP docs

I've been reading (and reading, and reading) about '.htaccess' and
'mysql.default_host' and what to set and how to set; or at least I'm trying
to read and understand.

It is my understanding that I can do this in my .htaccess file 
(or httpd.conf)...

<Directory /home/walter/htdocs/magicdb>
   php_value mysql.default_user myUser
   php_value mysql.default_password myPassWord
   php_value mysql.default_host localhost

And then do this...

   $link = mysql_connect ( ) or die;

and all the info will be "assumed"

If so, I can't make it happen.

I have a need to have my code library run on 3 different servers, each
against their own mySQL server, each with different login info (don't ask)
so I figured this would be a great way to have the same code base and just
change the .htaccess (or httpd.conf) file on each machine.

Any ideas why this is not working, or any ideas on how to make this better?




class database
   var $host = "localhost";
   var $user = "myUser";
   var $pass = "myPassWord";

   var $d_base;
   var $conx;
   var $db;
   var $result;

   function connectdb ( $db_name )
      $this->d_base = $db_name;

//    $this->conx = mysql_connect ( $this->host, $this->user, $this->pass )
      $this->conx = mysql_connect ( ) or
          $this->sql_error ( "db-connect", mysql_error() );

      $this->db = mysql_select_db ( $this->d_base, $this->conx ) or
          $this->sql_error ( "db-select", mysql_error() );

   function closedb ( )
      mysql_close ( $this->conx ) or sql_error ( "db-close",
mysql_error() );

   // I added this, it felt better than the other way.
   function querydb ( $query )
      $this->result = mysql_query($query);

   // This I added, he didn't have this defined.
   function sql_error ( $a, $b )
      echo $a . ' x  ' . $b;


More information about the thelist mailing list