npsari Posted March 7, 2007 Share Posted March 7, 2007 I have been trying to create database This is the code I am using <HTML> <HEAD> <TITLE>Connect & Create</TITLE> <BODY> <?php $con = mysql_connect("localhost","my name","my password"); if ($con) { print("Done connecting<BR>\n"); } else { print("Not done connecting<BR>\n"); } if (mysql_create_db ("Newdatabase", $con)) { print("Created<BR>\n"); } else { print("Not Created<BR>\n"); } mysql_close($con); ?> </HEAD> </BODY> </HTML> This is the result I get: Done connecting Fatal error: Call to undefined function: mysql_create_db() in /home/npsari/public_html/trials/connectcreateinternet.php on line 23 Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/ Share on other sites More sharing options...
trq Posted March 7, 2007 Share Posted March 7, 2007 mysql_create_db() has been depricated. Just use sql. eg; <?php // connect to server if (mysql_query('CREATE DATABASE Newdatabase')) { echo "success"; } else { echo mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201647 Share on other sites More sharing options...
npsari Posted March 7, 2007 Author Share Posted March 7, 2007 hey, thanks! However, this time it tells me: Access denied for user 'my name'@'localhost' to database 'Newdatabase' Do you know why? By the way, which username and password do i use? My server's or my mysql Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201658 Share on other sites More sharing options...
iceman400 Posted March 7, 2007 Share Posted March 7, 2007 username and password - thats y it gave you the access denied error. if you used default settings when setting up your mysql server, username is "root" and password is empty (if you didn't set 1) or the one u set when installing the mysql server. Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201663 Share on other sites More sharing options...
npsari Posted March 7, 2007 Author Share Posted March 7, 2007 My sql is provided by the company i am hosting at I used "root" and No password this is what i got: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /home/npsari/public_html/trials/connectcreate2.php on line 8 Not done connecting Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/npsari/public_html/trials/connectcreate2.php on line 26 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/npsari/public_html/trials/connectcreate2.php on line 26 Access denied for user 'nobody'@'localhost' (using password: NO) Does that mean anything? An this is the code I used: <?php $con = mysql_connect("localhost","root",""); if ($con) { print("Done connecting<BR>\n"); } else { print("Not done connecting<BR>\n"); } // connect to server if (mysql_query('CREATE DATABASE Newdatabase')) { echo "success"; } else { echo mysql_error(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201668 Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 set a password then use the code ok. Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201671 Share on other sites More sharing options...
npsari Posted March 7, 2007 Author Share Posted March 7, 2007 Ohh, so I go to mySQL and create a user name "root" and a password of my choice is that what you mean? Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201672 Share on other sites More sharing options...
bwochinski Posted March 7, 2007 Share Posted March 7, 2007 If you're using just standard shared hosting from any number of hosting providers, you likely do not have permissions to create databases through SQL. Most probably you have to add the database and user through whatever control panel interface your webhost provides, or if they don't, send them a request asking for it to be created. Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201722 Share on other sites More sharing options...
Snooble Posted March 7, 2007 Share Posted March 7, 2007 log into your hosting site and they should have phpmyadmin if you have sql capabilities. If not i doubt they allow you. Give MYSQL PHP FREE HOST a search on google. Snooble Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201731 Share on other sites More sharing options...
azaad Posted March 7, 2007 Share Posted March 7, 2007 My sql is provided by the company i am hosting at I used "root" and No password this is what i got: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: NO) in /home/npsari/public_html/trials/connectcreate2.php on line 8 Not done connecting Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/npsari/public_html/trials/connectcreate2.php on line 26 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/npsari/public_html/trials/connectcreate2.php on line 26 Access denied for user 'nobody'@'localhost' (using password: NO) Does that mean anything? An this is the code I used: <?php $con = mysql_connect("localhost","root",""); if ($con) { print("Done connecting<BR>\n"); } else { print("Not done connecting<BR>\n"); } // connect to server if (mysql_query('CREATE DATABASE Newdatabase')) { echo "success"; } else { echo mysql_error(); } ?> if u gave space b/w the two double quotes then the password is "no". so try it by deleting the space . Quote Link to comment https://forums.phpfreaks.com/topic/41618-i-have-been-trying-4-days-now-to-create-database-but-i-cant/#findComment-201887 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.