simulation of sql server on wamp server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
finkel
Forum Newbie
Posts: 6
Joined: Sat Jan 10, 2009 2:57 am

simulation of sql server on wamp server

Post by finkel »

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)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: simulation of sql server on wamp server

Post by requinix »

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:

Code: Select all

CREATE DATABASE my_db;
GRANT ALL PRIVILEGES ON *.* TO peter@localhost IDENTIFIED BY "abc123";
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.
finkel
Forum Newbie
Posts: 6
Joined: Sat Jan 10, 2009 2:57 am

Re: simulation of sql server on wamp server

Post by finkel »

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);
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: simulation of sql server on wamp server

Post by requinix »

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