Zanzlanz Posted November 27, 2011 Share Posted November 27, 2011 Hello! I'm planning a Flash game that uses a PHP database, but I've never made a database before. Website: Zanzlanz.com What is my username? Is it USERNAME_DB1 or is it just DB1? And let's just say my MySQL password is "1234" So how do I use mySQL_connect to go to my database? I'm very... mediocre in PHP, so please explain it detailed for me! Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/ Share on other sites More sharing options...
Adam Posted November 27, 2011 Share Posted November 27, 2011 Are you asking us for your MySQL username? Have you read the manual on how to use it? Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291442 Share on other sites More sharing options...
Zanzlanz Posted November 27, 2011 Author Share Posted November 27, 2011 Well my website provider: awardspace, gave me my username as (for example): Zanzlanz1_data I have no control over the Zanzlanz1_ part. But when I use the script: <?php $connect = @mysql_connect("zanzlanz.com", "Zanzlanz1_data", "1234"); if($connect) { echo("Success"); } else { echo("Failure"); } ?> It always says "Failure." Since I'm new to the database, I know I'm doing something wrong. http://zanzlanz.com/database.php Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291453 Share on other sites More sharing options...
fenway Posted November 27, 2011 Share Posted November 27, 2011 And what did your "website provider" say? Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291471 Share on other sites More sharing options...
Zanzlanz Posted November 27, 2011 Author Share Posted November 27, 2011 And what did your "website provider" say? Here, I attached a file of it. It says "Database name is the same as the database username" but it doesn't seem to work that way... Again, is my syntax look correct at least? And last thing to mention: I'm using MySQL Manager if that changes anything. And thanks for the help so far. It's greatly appreciated! [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291482 Share on other sites More sharing options...
fenway Posted November 27, 2011 Share Posted November 27, 2011 If someone other than you selected the credentials, then that someone is the only one who can help you. Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291568 Share on other sites More sharing options...
Zanzlanz Posted November 27, 2011 Author Share Posted November 27, 2011 If someone other than you selected the credentials, then that someone is the only one who can help you. No it's me. I just don't what to write in the PHP script. I'm not going to literally give away my username and password! :\ Oh well. I guess I'm just that terrible Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291572 Share on other sites More sharing options...
Adam Posted November 27, 2011 Share Posted November 27, 2011 If you know your username and password, as explained clearly in the manual pass them as the second and third paramters to mysql_connect. Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291576 Share on other sites More sharing options...
Zanzlanz Posted November 27, 2011 Author Share Posted November 27, 2011 If you know your username and password, as explained clearly in the manual pass them as the second and third paramters to mysql_connect. Okay that's what I thought. So "Zanzlanz1_data" would be an example of my username. And then the first parameter, would that be my website "website.com" because it doesn't want to work. I've seen examples with "website.com:3301". Why is there a port number? Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291589 Share on other sites More sharing options...
Pikachu2000 Posted November 27, 2011 Share Posted November 27, 2011 You need to ask your provider what to use as the server address. Some are IP address, some hostname, some localhost, some have a custom post number, some don't. More than likely, all of this information is available in the ISP's FAQ's. If not, then their tech support people should be able to rattle it off on the phone. Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291593 Share on other sites More sharing options...
Zanzlanz Posted November 27, 2011 Author Share Posted November 27, 2011 You need to ask your provider what to use as the server address. Some are IP address, some hostname, some localhost, some have a custom post number, some don't. More than likely, all of this information is available in the ISP's FAQ's. If not, then their tech support people should be able to rattle it off on the phone. Okay thanks for all of your help! Let's see if I can't get the resolved Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1291606 Share on other sites More sharing options...
Dazman2011 Posted November 29, 2011 Share Posted November 29, 2011 Typically I use something like this:- $connection = mysql_connect("localhost","database_user","password"); if (!$connection) { die('Could not connect: ' . mysql_error()); } else { mysql_select_db("database_name", $connection); } ... which tends to work on shared servers with cpanel access. You do need to include the full name of the user and database including the USERNAME_ that precedes the name you might have given it in cpanel. Localhost or 127.0.0.1 is possibly the bit you are probably missing ... because you are using the domain name the server may be thinking of it as an external domain rather than itself. Using localhost has worked for me in most cases. Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1292288 Share on other sites More sharing options...
Zanzlanz Posted November 29, 2011 Author Share Posted November 29, 2011 Typically I use something like this:- $connection = mysql_connect("localhost","database_user","password"); if (!$connection) { die('Could not connect: ' . mysql_error()); } else { mysql_select_db("database_name", $connection); } ... which tends to work on shared servers with cpanel access. You do need to include the full name of the user and database including the USERNAME_ that precedes the name you might have given it in cpanel. Localhost or 127.0.0.1 is possibly the bit you are probably missing ... because you are using the domain name the server may be thinking of it as an external domain rather than itself. Using localhost has worked for me in most cases. Hello Dazman2011, This is absolutely perfect! Thanks! I'll go try this out and see if it works for me. I always thought localhost meant using the client side only. So will this work if I have a Flash file accessing the PHP script from a different domain? Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1292354 Share on other sites More sharing options...
Zanzlanz Posted November 29, 2011 Author Share Posted November 29, 2011 die('Could not connect: ' . mysql_error()); Okay well here's what happened: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1292402 Share on other sites More sharing options...
Zanzlanz Posted November 29, 2011 Author Share Posted November 29, 2011 Okay I finally found just the right thing for the server name: pdb1.awardspace.com Thank you everyone whose been such a fantastic help! I will continue to use these forums. The first impression was amazing. Quote Link to comment https://forums.phpfreaks.com/topic/251865-mysql_connecthow-to-use/#findComment-1292409 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.