49 users online (1 members and 48 guests)  

Thread: database error


  Results 1 to 5 of 5

Related

  1. How to Decode the data from Database using database handler?    Forum: Search Engine Optimization - SEO - Forum
    Replies: 1
  2. Database error in vCard PRO    Forum: Website Scripts Forum
    Replies: 0
  3. database connection error    Forum: Databases
    Replies: 4
  4. Replies: 0
  5. Error MySQL Error: 1064 - subqueries    Forum: PHP Forum
    Replies: 0
  1. #1
    BillDB's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2007
    Posts
    3

    database error

    Hi to all
    Can someone help me with the following error?
    Warning: mysql_connect() []: Access denied for user 'uaeshama_gallery'@'localhost' (using password: YES) in /home/public_html/gallery/includes/db_mysql.php on line 39

    DB Error: Could not connect to the database server (localhost, _gallery).


    THIS is The file in question

    Code:
    if (!defined('ROOT_PATH')) {
    die("Security violation");
    }
     
    class Db {
    var $no_error = 0;
    var $connection;
    var $query_id = 0;
    var $query_count = 0;
    var $query_time = 0;
    var $query_array = array();
    var $table_fields = array();
     
    function Db($db_host, $db_user, $db_password = "", $db_name = "", $db_pconnect = 0) {
    $connect_handle = ($db_pconnect) ? "mysql_pconnect" : "mysql_connect";
    if (!$this->connection = $connect_handle($db_host, $db_user, $db_password)) {
    $this->error("Could not connect to the database server ($db_host, $db_user).", 1);
    }
    if ($db_name != "") {
    if (!@mysql_select_db($db_name)) {
    @mysql_close($this->connection);
    $this->error("Could not select database ($db_name).", 1);
    }
    }
    return $this->connection;
    }
     
    function close() {
    if ($this->connection) {
    if ($this->query_id) {
    @mysql_free_result($this->query_id);
    }
    return @mysql_close($this->connection);
    }
    else {
    return false;
    }
    }
     
    function query($query = "") {
    unset($this->query_id);
    if ($query != "") {
    if ((defined("PRINT_QUERIES") && PRINT_QUERIES == 1) || (defined("PRINT_STATS") && PRINT_STATS == 1)) {
    $startsqltime = explode(" ", microtime());
    }
    if (!$this->query_id = @mysql_query($query, $this->connection)) {
    $this->error("<b>Bad SQL Query</b>: ".htmlentities($query)."<br /><b>".mysql_error()."</b>");
    }
    if ((defined("PRINT_QUERIES") && PRINT_QUERIES == 1) || (defined("PRINT_STATS") && PRINT_STATS == 1)) {
    $endsqltime = explode(" ", microtime());
    $totalsqltime = round($endsqltime[0]-$startsqltime[0]+$endsqltime[1]-$startsqltime[1],3);
    $this->query_time += $totalsqltime;
    $this->query_count++;
    }
    if (defined("PRINT_QUERIES") && PRINT_QUERIES == 1) {
    $query_stats = htmlentities($query);
    $query_stats .= "<br><b>Querytime:</b> ".$totalsqltime;
    $this->query_array[] = $query_stats;
    }
    return $this->query_id;
    }
    }
     
    function fetch_array($query_id = -1, $assoc = 0) {
    if ($query_id != -1) {
    $this->query_id = $query_id;
    }
    if ($this->query_id) {
    return ($assoc) ? mysql_fetch_assoc($this->query_id) : mysql_fetch_array($this->query_id);
    }
    }
     
    function free_result($query_id = -1) {
    if ($query_id != -1) {
    $this->query_id = $query_id;
    }
    return @mysql_free_result($this->query_id);
    }
     
    function query_firstrow($query = "") {
    if ($query != "") {
    $this->query($query);
    }
    $result = $this->fetch_array($this->query_id);
    $this->free_result();
    return $result;
    }
     
    function get_numrows($query_id = -1) {
    if ($query_id != -1) {
    $this->query_id = $query_id;
    }
    return mysql_num_rows($this->query_id);
    }
     
    function get_insert_id() {
    return ($this->connection) ? @mysql_insert_id($this->connection) : 0;
    }
     
    function get_next_id($column = "", $table = "") {
    if (!empty($column) && !empty($table)) {
    $sql = "SELECT MAX($column) AS max_id
    FROM $table";
    $row = $this->query_firstrow($sql);
    return (($row['max_id'] + 1) > 0) ? $row['max_id'] + 1 : 1;
    }
    else {
    return NULL;
    }
    }
     
    function get_numfields($query_id = -1) {
    if ($query_id != -1) {
    $this->query_id = $query_id;
    }
    return @mysql_num_fields($this->query_id);
    }
     
    function get_fieldname($query_id = -1, $offset) {
    if ($query_id != -1) {
    $this->query_id = $query_id;
    }
    return @mysql_field_name($this->query_id, $offset);
    }
     
    function get_fieldtype($query_id = -1, $offset) {
    if ($query_id != -1) {
    $this->query_id = $query_id;
    }
    return @mysql_field_type($this->query_id, $offset);
    }
     
    function affected_rows() {
    return ($this->connection) ? @mysql_affected_rows($this->connection) : 0;
    }
     
    function is_empty($query = "") {
    if ($query != "") {
    $this->query($query);
    }
    return (!mysql_num_rows($this->query_id)) ? 1 : 0;
    }
     
    function not_empty($query = "") {
    if ($query != "") {
    $this->query($query);
    }
    return (!mysql_num_rows($this->query_id)) ? 0 : 1;
    }
     
    function get_table_fields($table) {
    if (!empty($this->table_fields[$table])) {
    return $this->table_fields[$table];
    }
    $this->table_fields[$table] = array();
    $result = $this->query("SHOW FIELDS FROM $table");
    while ($row = $this->fetch_array($result)) {
    $this->table_fields[$table][$row['Field']] = $row['Type'];
    }
    return $this->table_fields[$table];
    }
     
    function error($errmsg, $halt = 0) {
    if (!$this->no_error) {
    echo "<br /><font color='#FF0000'><b>DB Error</b></font>: ".$errmsg."<br />";
    if ($halt) {
    exit;
    }
    }
    }
    } // end of class
    ?>
    Last edited by vinyl-junkie; 08-01-2007 at 06:07 AM. Reason: Added code tags

  2. #2
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: database error

    First of all, you'd be better off using mysql_connect instead of mysql_pconnect. Find out why here.

    Secondly, echo the parameters you're using for your database name, username and password. Are they correct? If so, you may need to check with your web host to find out the proper way to connect with your database.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more

  3. #3
    flann's Avatar
    New User

    Status
    Offline
    Join Date
    May 2007
    Posts
    18

    Re: database error

    did you add the user to the database? I know when I first started, I would create a database and a user, however I would forget to add that user to that database.

  4. #4
    BillDB's Avatar
    New User

    Status
    Offline
    Join Date
    Jul 2007
    Posts
    3

    Re: database error

    Vinyl
    Flann
    Thanks gentlemen !
    Your help is much appreciated indeed.
    I contacted tech support at host co. they confirmed your diagnostics. However the data was imported from a forum -ex owner. I have no way of knowing what password he used....can I create/add a user /new password per Flann's suggestion?
    I am newbie to all this so if someone can help with step by step on how to.
    Again many thanks to all

  5. #5
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: database error

    Quote Originally Posted by BillDB View Post
    Vinyl
    Flann
    Thanks gentlemen ! Your help is much appreciated indeed.
    I'm not a gentleman (I'm a lady), but you're welcome!

    I contacted tech support at host co. they confirmed your diagnostics. However the data was imported from a forum -ex owner. I have no way of knowing what password he used....can I create/add a user /new password per Flann's suggestion?
    Yes, that is correct. Do that, then change your database connection parameters in your code, and you should be all set.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more



Tags for this Thread