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...