-1

I am trying to deploy php application on Xampp server and getting error on index.php

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\xampp\php-inventory\lib\database.php on line 85
Warning: mysql_error() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\xampp\php-inventory\lib\database.php on line 85
CDatabase::Connect() error

This is what the function that errors out:

function Connect($connect_params = "") {
    extract($connect_params);
    //resource mysql_connect ( [string server [, string username [, string password [, bool new_link !!! [, int client_flags ]]]]] )
    $this - > conn_id = mysql_connect($server, $login, $password, True) or die("CDatabase::Connect() error ".mysql_error($this - > conn_id));

    if ($default != "") $this - > SelectDB($default);
}

I have tried changing "true" to 1 still the same. I am new to php and was not able to find anything helpful. There is no password set for mysql.

Amelia
  • 2,887
  • 2
  • 24
  • 39
Harry
  • 15
  • 1
  • 3
  • bad start, and incomplete code snippet .. – Gntem Feb 09 '13 at 21:11
  • Your password is wrong – Explosion Pills Feb 09 '13 at 21:12
  • 1
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. – Amelia Feb 09 '13 at 21:56

2 Answers2

0

Your password is wrong. Fix that. You probably shouldn't be using root as the user either. Also, don't use ext/mysql

The reason you get the warning on mysql_error is because connection errors don't return a resource (they can't make the connection after all). Mysql_error needs the resource to get the error from the DB connection. Without the connection, it can't. Fortunately, mysql_connect reports the error on its own.

Explosion Pills
  • 183,406
  • 48
  • 308
  • 385
0
  1. "... Access denied for user 'root'@'localhost' (using password: YES) ..." The user name or password is/are wrong.
  2. What you mean with "There is no password set for mysql." ?
  3. Why root user?
  4. The second Warning:

mysql_error() expects parameter 1 to be resource, boolean given

because: "Returns a MySQL link identifier on success or FALSE on failure." http://php.net/manual/en/function.mysql-connect.php 5. change or die ( ... ) with

if(!$this->conn_id) { // Error }

Gabe
  • 83
  • 1
  • 10