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? 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 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 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 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?? 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 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? 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" 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? 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" 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 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? 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. 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. 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... 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. 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. 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! 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? 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. 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 Link to comment https://forums.phpfreaks.com/topic/48870-cant-connect/#findComment-240525 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.