Jump to content

PHP MYSQL remote connection --please help


worldcomingtoanend

Recommended Posts

now i just signed up for my remote mysql database after which i created the code below:

 

<?php
$mysql_host = "ipadress";
$mysql_database = "name";
$mysql_user = "user";
$mysql_password = "wowowow";


$connection = mysql_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database);

$link = mysql_select_db($mysql_database,$connection) or die(mysql_error());

switch ($link)
{

case TRUE:

echo "Connected ThankYou...";

break;

case FALSE:

echo "Not Connected";

}

?>

 

surprisingly if i run my server and run the script nothing happens at all.  Not even an error message is displayed.  it just displays a blank page.  where can i be going wrong.  thank u.

Link to comment
Share on other sites

Not that this would be causing the problem, but the 4th parameter for mysql_connect isn't the database name; read the manual for more info. The methods you've used for connecting are a little unorthodox, but I can't see any reason why this wouldn't at least display an error. Ensure all error reporting is on and that the connection values are all correct... Perhaps then debug the code line by line to find the point where the code beaks.

Link to comment
Share on other sites

Assuming that your connection data is correct for your specific server i.e. host name, user name etc.

 

Try using an if condtional instead of a switch statement. Something like:

 

if ($link) {
    echo "<h1>Connection successful</h1>\n";
} else {
    echo "<h1>Connection failed!</h1><br/>Debug: " . mysql_error($link) . "<br/>\n";
}

Link to comment
Share on other sites

Assuming that your connection data is correct for your specific server i.e. host name, user name etc.

 

Try using an if condtional instead of a switch statement. Something like:

 

if ($link) {
    echo "<h1>Connection successful</h1>\n";
} else {
    echo "<h1>Connection failed!</h1><br/>Debug: " . mysql_error($link) . "<br/>\n";
}

 

Shouldn't matter as switch's based on loose comparison.

Link to comment
Share on other sites

Assuming that your connection data is correct for your specific server i.e. host name, user name etc.

 

Try using an if condtional instead of a switch statement. Something like:

 

if ($link) {
    echo "<h1>Connection successful</h1>\n";
} else {
    echo "<h1>Connection failed!</h1><br/>Debug: " . mysql_error($link) . "<br/>\n";
}

 

Shouldn't matter as switch's based on loose comparison.

 

guys i hv tried all i can but nothing seems to work...its strange really at least if an error message was shown i could work it around but its just silent...other php scripts work fine and dispay errors, etc but this one is just silent

Link to comment
Share on other sites

I would actually point to the first response from MrAdam. It seems to me like your assigning the database name twice!

 

Passing your $mysql_database variable once as a parameter in the mysql_connect() statement should be enough. Only if you're connecting with just the host, user_name, password would you then need a separate mysql_select_db() statement AFAIN.

 

I can post an example of the script I use to connect if that will help?

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.