gsquare567 Posted April 27, 2007 Share Posted April 27, 2007 Could not connect: Access denied for user 'ODBC'@'localhost' (using password: NO) <?php $con = mysql_connect("localhost"); 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 also tried localhost:3306 and no paramaters but same error =S any1 know how to fix that? Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/ Share on other sites More sharing options...
rallokkcaz Posted April 27, 2007 Share Posted April 27, 2007 <?php $dbhost = 'localhost'; $dbname = 'db'; $dbusername = 'username'; $dbuserpass = 'password'; mysql_select_db($dbname) or die('Cannot select database'); $con = mysql_connect ($dbhost, $dbusername, $dbuserpass); if (mysql_query("CREATE DATABASE my_db",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } mysql_close($con); ?> this should work Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239523 Share on other sites More sharing options...
rallokkcaz Posted April 27, 2007 Share Posted April 27, 2007 or you could just go into PHPMyAdmin that would make it even easier Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239525 Share on other sites More sharing options...
gsquare567 Posted April 27, 2007 Author Share Posted April 27, 2007 but i dont have a database yet, its my first time Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239526 Share on other sites More sharing options...
rallokkcaz Posted April 27, 2007 Share Posted April 27, 2007 well do u have PHPMyAdmin?? Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239528 Share on other sites More sharing options...
gsquare567 Posted April 27, 2007 Author Share Posted April 27, 2007 yeah, made a table but i dont know how to get the code or how it's going to work =S Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239530 Share on other sites More sharing options...
rallokkcaz Posted April 27, 2007 Share Posted April 27, 2007 what exactly do u want to do with this table? Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239531 Share on other sites More sharing options...
gsquare567 Posted April 27, 2007 Author Share Posted April 27, 2007 tryin to make an auth system, where i'll host the code and add in &$username=test123&$password=test456 or somethin like that and the php code will check the db and if they match echoes "VALID" Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239532 Share on other sites More sharing options...
rallokkcaz Posted April 27, 2007 Share Posted April 27, 2007 so basically your trying to make a login script? Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239533 Share on other sites More sharing options...
gsquare567 Posted April 27, 2007 Author Share Posted April 27, 2007 yes, precisely, so why isnt my mysql_connect working? i got wamp and it says "WAMP5 - All services running - server Offline" Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239534 Share on other sites More sharing options...
rallokkcaz Posted April 27, 2007 Share Posted April 27, 2007 here is a simple but effective login, register script http://www.trap17.com/index.php/simple-user-system_t46278.html its really easy to modify Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239536 Share on other sites More sharing options...
gsquare567 Posted April 27, 2007 Author Share Posted April 27, 2007 thanks, but i dont think i understand how to work phpmyadmin correctly. i made a table, but how do i put in my php code to work with it? Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239540 Share on other sites More sharing options...
AndyB Posted April 27, 2007 Share Posted April 27, 2007 I think now would be a really good time to read a simple tutorial on databases, before you get irretrievably confused. Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239555 Share on other sites More sharing options...
neel_basu Posted April 27, 2007 Share Posted April 27, 2007 Use $con = mysql_connect("localhost", "Your_user_name", "Your_password"); If you are doing it at your Home PC the User_name would be root. Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239596 Share on other sites More sharing options...
gsquare567 Posted April 27, 2007 Author Share Posted April 27, 2007 i know how to make a mysql database. how about my question... how can i take away that error... Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239899 Share on other sites More sharing options...
neel_basu Posted April 27, 2007 Share Posted April 27, 2007 Dont use mysql_connect("localhost"); Use Use $con = mysql_connect("localhost", "Your_user_name", "Your_password"); If you are doing it at your Home PC the User_name would be root. and in your code you are not using any user name or password. Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239908 Share on other sites More sharing options...
KevinM1 Posted April 27, 2007 Share Posted April 27, 2007 First, since the original poster is a newbie, I wouldn't recommend using PHP to create new databases and tables. phpMyAdmin is far simpler in that regard. Second, a database connection script typically looks like the following: <?php /* dbconnect.php -- database connection script */ DEFINE ('HOST', 'hostName'); DEFINE ('USER', 'userName'); DEFINE ('PASSWORD', 'password'); DEFINE ('MYDB', 'dbName'); $dbc = mysql_connect(HOST, USER, PASSWORD) or DIE('Could not connect to the database: ' . mysql_error()); mysql_select_db(MYDB, $dbc) or DIE('Could not select the database: ' . mysql_error()); ?> For security reasons, you should stick this script outside of your public_html folder. You can access it by simply doing the following: require('../dbconnect.php'); You should only include it when you're going to be accessing the database. Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-239914 Share on other sites More sharing options...
gsquare567 Posted April 27, 2007 Author Share Posted April 27, 2007 ok, now i get Could not select the database: Unknown database 'authinfos' but it connected properly! one step further thanks! Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-240067 Share on other sites More sharing options...
gsquare567 Posted April 28, 2007 Author Share Posted April 28, 2007 so how can i get rid of that error? Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-240520 Share on other sites More sharing options...
neel_basu Posted April 28, 2007 Share Posted April 28, 2007 There is no database with the name authinfos. Make sure about the database name. Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-240521 Share on other sites More sharing options...
gsquare567 Posted April 28, 2007 Author Share Posted April 28, 2007 im an idiot Quote Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-240525 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.