Connection failed: Couldn't make the connection to localhost

Hi All,

I have an application that was running very well. the server started malfunction and I had it reinstall with red5.2. it has mysql and php. but when i run the php program,the error

Connection failed: Couldn’t make the connection to localhost.

is appearing.

what could e the problem.

I would guess that this message is from your application, and likely related to the database. Check to see if the mysql(i) extension is available/enabled in your PHP installation.

thanks. this was my problem. the error was coming from my application.

However, i cannot connect to mysql using php. no error is given even when the databsae, passwd are wrong.

where am i going wrong

Increase the level of reporting within your application to the following, it should point you in the right direction.


error_reporting(-1);
ini_set('display_errors', true);

Hi,

Still having the same issue. should I do it in the php.ini

Can do.

AnthonySterling, thanks for the help thus far. i dont what to do.

Enable all the error message in the php.ini

display_errors = On
but things cant work.

Have you changed the error reporting too?

Upload this test script to your server and post the output here.


<?php
foreach(get_loaded_extensions() as $extension){
  printf("%s<br />\
", $extension);
}

HEre you are

libxml
xml
wddx
tokenizer
sysvshm
sysvsem
sysvmsg
standard
SimpleXML
sockets
SPL
shmop
session
Reflection
pspell
posix
mime_magic
iconv
hash
gmp
gettext
ftp
exif
date
curl
ctype
calendar
bz2
zlib
pcre
openssl
apache2handler
dbase
ldap

You don’t have the MySQL extension loaded and/or enabled. You need to enable it. :slight_smile:

Hi AnthonySterling,

How can i have the MYSQL extension enabled. I will appreciate you quick as I require to launch the product tomorrow.

Here is the extensions after a few changes.

libxml
xml
wddx
tokenizer
sysvshm
sysvsem
sysvmsg
standard
SimpleXML
sockets
SPL
shmop
session
Reflection
pspell
posix
mime_magic
iconv
hash
gmp
gettext
ftp
exif
date
curl
ctype
calendar
bz2
zlib
pcre
openssl
apache2handler
dbase
ldap
mysqli

AM i still missing something

It looks like you now have the mysql extension loaded, which is good news.

What output are you getting from your application now? It maybe worth taking a look at the error log too. :slight_smile:

the code

 <?php
$dbserver= "localhost";     // Hostname of your MySQL server
$db = "simrep";      // Name of your MySQL database
$dbuser = "root";       // MySQL user with access to $db
$dbpassword = "passwd";   // Password for MySQL user

/* Connect to the MySQL server */
$link = @mysql_connect ($dbserver, $dbuser, $dbpassword);
if (!$link){
   echo ( "Unable to connect to db" );
exit();
}

/* Select the database */
if (!mysql_select_db ($db, $link) ){
exit ();
}
else{
   echo ( "Able to connect to db<br>" );
        $s="select * from sessions";
        $q=mysql_query($s) or die(mysql_error());
        while($r=mysql_fetch_array($q))
        echo $r[2]."<br>";
}

?>

is outputing nothing when i have data in the database. strange, it was working initially. No error message

Try this:-


<?php
error_reporting(-1);
ini_set('display_errors', true);

$dbserver= "localhost";     // Hostname of your MySQL server
$db = "simrep";      // Name of your MySQL database
$dbuser = "root";       // MySQL user with access to $db
$dbpassword = "passwd";   // Password for MySQL user

/* Connect to the MySQL server */
$link = mysql_connect($dbserver, $dbuser, $dbpassword);

if(!$link){
  echo 'Unable to connect to server: ' . mysql_error();
  exit;
}

/* Select the database */
if(!mysql_select_db ($db, $link) ){
  echo 'Cannot select database: ' . mysql_error();
  exit;
}else{
  $s = "select * from sessions";
  $q = mysql_query($s) or die(mysql_error());
  while($r = mysql_fetch_array($q)){
    echo $r[2] . '<br>';
  }
}
?>

PHP Fatal error: Call to undefined function mysql_connect() in /var/www/html/test.php on line 9

Right, so we don’t have the mysql extension available. Do you have CLI access to the server?

If so, try:-


yum install php-mysql

Loading “security” plugin
Loading “rhnplugin” plugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Parsing package install arguments
No package php-mysql available.
Nothing to do

Let’s get this moved over to the Server bods and see what we can do for you, I’m not familiar with Red Hat I’m afraid.

Feel free to research php-mysql installation yourself though, given your deadline.

Hi When i Move it to another Server, it works fine.