I couldn't create DB with this php code.

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
kchoi85
Forum Newbie
Posts: 1
Joined: Wed Oct 27, 2010 12:20 am

I couldn't create DB with this php code.

Post by kchoi85 »

<?php

if ($dbc = mysql_connect('localhost', 'statgcom', 'M520choiw.')) {
print '<p> successfully connected to MySQL!</[>';


if (@mysql_query('CREATE DATABASE myblog')) {

print '<p> the database has been created!</p>';

} else {
print '<p> Failed to create DB
<br /> ' . mysql_error() . '.
</p>';
}

if (@mysql_select_db('myblog')) {
print '<p> the database has been selected.</p>';
} else {
print '<p> could not select the database because <br /> ' . mysql_error() . '.
</p>';
}

mysql_close(); // close connection

} else {

print '<p> could not connect to mysql <br /> ' . mysql_error() . '.
</p>';

}

?>

#################
The result was this


successfully connected to MySQL!
Failed to create DB
Access denied for user 'statgcom'@'localhost' to database 'myblog'.

could not select the database because
Access denied for user 'statgcom'@'localhost' to database 'myblog'.

###############################

Can you see the problem?
Thank you.
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

Re: I couldn't create DB with this php code.

Post by iijb »

hi,
Check your username and password for mysql is correct or not. I think there is a dot in your password.

Regards
iijb
Post Reply