akiratoya13 Posted November 10, 2007 Share Posted November 10, 2007 hello all, I have install apache, php, and mysql. but when I connect mysql to php, that's give me an error.. and of course I think I must create database first.. but I don't know how.. please someone tell me.. thank you. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 first of all what error does it give you ? to create a database you would have to use the following command CREATE DATABASE `test1` ; which will create a database name test1 Quote Link to comment Share on other sites More sharing options...
akiratoya13 Posted November 10, 2007 Author Share Posted November 10, 2007 first of all what error does it give you ? to create a database you would have to use the following command CREATE DATABASE `test1` ; which will create a database name test1 I wrote code like you.. CREATE DATABASE 'test' ; I'm following your code and it get me : Parse error: parse error, unexpected T_STRING in C:\AppServ\www\test.php on line 3. what was that? before error it must because I didn't have database.. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 can you post your code of test1 ? Quote Link to comment Share on other sites More sharing options...
akiratoya13 Posted November 10, 2007 Author Share Posted November 10, 2007 <?php CREATE DATABASE 'test'; ?> my code is like that... wrong? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 well you have to first connect to a server <?php mysql_connect("localhost","root",""); mysql_query("CREATE DATABASE 'test'"); ?> more information on mysql functions at http://php.net/mysql Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 also I think you should take a look at the php manual http://php.net/manual/en/index.php have you got explosure to any other programming languages ? Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 try this code too it should work <?php mysql_connect("localhost","root",""); mysql_create_db("test"); ?> Quote Link to comment Share on other sites More sharing options...
akiratoya13 Posted November 10, 2007 Author Share Posted November 10, 2007 now I'm following from that site to create database <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } $sql = 'CREATE DATABASE my_db'; if (mysql_query($sql, $link)) { echo "Database my_db created successfully\n"; } else { echo 'Error creating database: ' . mysql_error() . "\n"; } ?> and it gives me error : Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'mysql_user'@'localhost' (using password: YES) in C:\AppServ\www\test.php on line 2 Could not connect: Access denied for user 'mysql_user'@'localhost' (using password: YES) Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 you have to use the username and password that you entered while installing Mysql try this however $link = mysql_connect('localhost', 'root', ''); for that single line in your code, it might work Quote Link to comment Share on other sites More sharing options...
akiratoya13 Posted November 10, 2007 Author Share Posted November 10, 2007 first of all what error does it give you ? to create a database you would have to use the following command CREATE DATABASE `test1` ; which will create a database name test1 thanks it works... ^^ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.