Hi , i have a a wamp server installed and want to try using the mysql functions .
i understood that i have to installed a sql server .
How do i do it ?
Does someone can give me a link to a good one .
And most importantly how does it work with the wamp server ??????
for the following code :
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}mysql_close($con);
?>
i get the result:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'peter'@'localhost' (using password: YES) in c:\wamp\www\nisaion.php on line 2
Could not connect: Access denied for user 'peter'@'localhost' (using password: YES)
simulation of sql server on wamp server
Moderator: General Moderators
Re: simulation of sql server on wamp server
You already have a database server installed. If you didn't, mysql_connect would have given a different error message.
That's what the M in WAMP stands for: MySQL.
Your problem is that MySQL doesn't know about the peter@localhost user. As root run these commands:
In general you should not be using PHP to create databases: the root user should because then your user permissions need to be modified and you can't do it yourself.
(Technically you should only be getting privileges on my_db.* but since you're learning and this is your machine...)
If you want to test out the mysql_ functions, use different queries.
That's what the M in WAMP stands for: MySQL.
Your problem is that MySQL doesn't know about the peter@localhost user. As root run these commands:
Code: Select all
CREATE DATABASE my_db;
GRANT ALL PRIVILEGES ON *.* TO peter@localhost IDENTIFIED BY "abc123";(Technically you should only be getting privileges on my_db.* but since you're learning and this is your machine...)
If you want to test out the mysql_ functions, use different queries.
Re: simulation of sql server on wamp server
first of all thanks for your help .
i wrote the two lines above and it still does'nt work ;
<?php
CREATE DATABASE my_db;
GRANT ALL PRIVILEGES ON *.* TO peter@localhost IDENTIFIED BY "abc123";
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}mysql_close($con);
?>
i wrote the two lines above and it still does'nt work ;
<?php
CREATE DATABASE my_db;
GRANT ALL PRIVILEGES ON *.* TO peter@localhost IDENTIFIED BY "abc123";
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}mysql_close($con);
?>
Re: simulation of sql server on wamp server
Not to belittle you, but did that code I posted look like PHP code?
It's commands for MySQL. Open up a MySQL client (like the mysql.exe program) as the root user and try them.
It's commands for MySQL. Open up a MySQL client (like the mysql.exe program) as the root user and try them.