Jump to content

@mysql_connect(HOW, TO, USE);


Zanzlanz

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.