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
https://forums.phpfreaks.com/topic/86225-php-doesnt-connect-to-sql/
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();

 

 

?>

$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

<?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());
} 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.