Jump to content

PHP doesn't connect to SQL


turbo_h4

Recommended Posts

i have the very basic code and i can't seem to connect to my sql database.  here is my code, it's just testing so i included the password.

 

 

$hostname="xxxx";

$mysql_login="xxxx";

$mysql_password="xxxx";

$database="xxxx";

 

if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){

  die("Can't connect to database server.");   

}else{

echo 'connected';

  // select a database

    if (!(mysql_select_db("$database",$db))){

      die("Can't connect to database.");

    }

}

 

 

 

even if i change the server to something irrelevant i get the same blank page. doesn't show errors..

Link to comment
Share on other sites

thanks for the replies. this is what i have now, still doesn't work..

 

 

 

<?php

 

 

/*--------- DATABASE CONNECTION INFO---------*/

$hostname="xxxx";

$mysql_login="xxxx";

$mysql_password="xxxx";

$database="xxxx";

 

if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){

  mysql_error();   

}else{

 

  echo 'connected';

  // select a database

    if (!(mysql_select_db($database,$db))){

      mysql_error();

    }

}

 

 

 

 

mysql_close();

 

 

?>

Link to comment
Share on other sites

$hostname="*****";
$mysql_login="*****";
$mysql_password="*****";
$database="71874_new";

if (!mysql_pconnect($hostname, $mysql_login , $mysql_password)){
  mysql_error();   
}else{
  echo 'connected';
  // select a database
    if (!(mysql_select_db($database,$db))){
      mysql_error();
    }
} 

try.. is that your real connection info? you should not display that

Link to comment
Share on other sites

<?php
$hostname="xxxxx";
$mysql_login="xxxx";
$mysql_password="xxxx";
$database="xxxx";

$db = mysql_connect($hostname, $mysql_login , $mysql_password) or die(mysql_error()); //mysql_pconnect is BAD.

if (!$db)
{
   //Oh noes!   It be brokeded!
}
else
{
   echo 'connected';
   // select a database
   mysql_select_db($db) or die(mysql_error());
} 
?>

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.