Anyone know how to get rid of this f***ing thing? I've got all my config set right, it can connect to the database, but when I try to select the damn database it gives me this:
QUOTE
MySQL Error: 1046 No Database Selected


Here's the code for my database class, which I use to process all my database activity. I've got it writing to a log, which says that it connects to the database correctly, but won't select the database.

CODE
<?php

require_once("config.php");



class database {

   var $handle;

   var $db;

   var $result;

   var $config;



   function database() {

@       $this->handle = mysql_pconnect($mysql_host, $mysql_user, $mysql_pass);

       $log = fopen("log.txt",'a');

       if(!$this->handle) {

           fwrite($log,"Error: Could Not Connect to MySQL Database!nMySQL Error:n".mysql_errno()." ".mysql_error()."nnn");

           fclose($log);

           die("Error: Could Not Connect to MySQL Database!nMySQL Error:n".mysql_errno()." ".mysql_error());

       }

       else {

           fwrite($log, "Connected to MySQL Database Successfully!");

       }

@       $this->db = mysql_select_db($mysql_dbname, $this->handle);

       if(!$this->db) {

           fwrite($log,"Error: Could not select Database!nMySQL Error:n".mysql_errno()." ".mysql_error()."nn");

           fclose($log);

           die("Error: Could not select Database!nMySQL Error:n".mysql_errno()." ".mysql_error()."nn");

       }

       else {

           fwrite($log,"Selected MySQL Database Successfully!");

       }

   }

   function query($query) {

       @$result = mysql_query($query,$this->handle);

       $log = fopen("log.txt",'a');

       if(!$result) {

           fwrite($log,"Error: Query was not executed!nQuery: ".$query."nMysql Error:n".mysql_errno().": ".mysql_error()."nn");

           fclose($log);

           echo "Non-critical Error: Query was not executed!nQuery: ".$query."nMysql Error:n".mysql_errno().": ".mysql_error()."nn";

           return false;

       }

       else {

           fwrite($log,"Query Executed Successfully!nQuery: ".$query."nn");

           fclose($log);

           $this->result = $result;

       }

   }

   function getconfig() {

       if(empty($this->config)) {

           $result = $this->query("SELECT title, url, theme FROM config");

           if($result) {

               $this->config = mysql_fetch_array($result, MYSQL_ASSOC);

               return $this->config;

           }

           else {

               $this->config = false;

               return $this->config;

           }

       }

       else {

           return $this->config;

       }

   }

}



?>


I know the database exists, and I've got the right user set, but it still won't work!

 

 

 


Reply