Page 1 of 1

Problem in SQL server.

PostPosted: 26. December 2008 04:14
by safee
HI,
I am a new user of XAMPP. I can do and run codes of normal PHP files. But While trying with MySQL in PHP I have faced a problem.
My problem is,
When I try to use $con=mysql_connect("localhost","peter","abc123"); function I get an error message like this
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'peter'@'localhost' (using password: YES) in C:\xampp\htdocs\PHP_Mysql\Php_Sql.php on line 7
Couldnot Connect to the server: Access denied for user 'peter'@'localhost' (using password: YES)

My code is given bellow:
Code: Select all
 $con=mysql_connect("localhost","peter","abc123");
      if(!$con)
      {
       die("Couldnot Connect to the server: ".mysql_error());
      }
      //somecode
      if(mysql_query("CREATE DATABASE my_db", $con))
      {
       echo "Database created";
      }
      else
      {
       echo "Error Creating database: ".mysql_error();
      }
      //creating database
      mysql_select_db(my_db,$con);
      $sql= "CREATE TABLE persons
      (
       personID int NOT NULL AUTO_INCREAMENT,
       PRIMARY KEY(personID),
       FirstName varchar(15),
       LastName varchar(15),
       Age int,
      )";
      mysql_query("INSERT INTO Persons (FirstName, LastName, Age)
      VALUES ('Peter','Grafin', '35')");
      mysql_querry("INSERT INTO Persons(FirstName, LastName, Age)
      VALUES ('Glemn','Quagmire','33')");
      mysql_close($con);

If there is any solutions that anybody can give me...
I will verymuch happy...

Re: Problem in SQL server.

PostPosted: 26. December 2008 06:37
by Wiedmann
When I try to use $con=mysql_connect("localhost","peter","abc123"); function I get an error message like this:
Access denied for user 'peter'@'localhost' (using password: YES)

You have a MySQL user with the name "peter" and the password "abc123"?

Re: Problem in SQL server.

PostPosted: 26. December 2008 08:40
by safee
No. Actually I have installed XAMPP(Apache Freinds). Here I have an sql server with an php server. :idea:

Re: Problem in SQL server.

PostPosted: 26. December 2008 14:30
by Wiedmann
No.

Hm, so why do you use this username if you don't have such an user?

a) create such an user
b) or use the predefined root user (see readme_en.txt)

Re: Problem in SQL server.

PostPosted: 27. December 2008 05:02
by safee
Ahh thanks. I got it.