Pergunta

I am receiving the below MySQLI error when I try to connect to my DB:

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /nfs/c10/h03/mnt/144844/domains/trash.mysite.com/html/functions.php on line 43 Failed to connect to MySQL: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

My connection file:

<?php $host = 'internal-db.s144844.gridserver.com'; $user = 'db144844_db'; $password = '***********'; $db = 'db144844_db'; ?>

The functions file:

`

require('connection.php');

function sendMessage($message)
{
    // this line loads the library 
    require('twilio-php-master/Services/Twilio.php'); 

    $account_sid = '***'; 
    $auth_token = '***'; 
    $client = new Services_Twilio($account_sid, $auth_token); 

    $client->account->messages->create(array( 
        'To' => "5555555555", 
        'From' => "+6666666666", 
        'Body' => $message, 

    ));
}

function resetTrash()
{
    //this could be set to just go on a certain day like tuesday
    $connection=mysqli_connect($host , $user , $password , $db);

    //turn alerts off in the db cause we missed it or whatever
    if (mysqli_connect_errno()) 
    {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    mysqli_query($connection,"UPDATE trash SET done=0 WHERE id=1");

    mysqli_close($connection);

}

function markDone()
{
    //this could be set to just go on a certain day like tuesday
    $connection=mysqli_connect($host , $user , $password , $db);

    //turn alerts off in the db cause we missed it or whatever
    if (mysqli_connect_errno()) 
    {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    mysqli_query($connection,"UPDATE trash SET done=1 WHERE id=1");

    mysqli_close($connection);

}

?>`

This is line 43 from the second function:

$connection=mysqli_connect($host , $user , $password , $db);

My host MediaTemple says that they can connect fine from their side using my connection info but a socket error seems like it would be something to do with MySQL not my code.

I can log into the DB fine using phpMyAdmin and such.

Foi útil?

Solução

You are simply forgetting function parameters:

function resetTrash(){
    $connection=mysqli_connect($host , $user , $password , $db);
                               ^^^^^   ^^^^^   ^^^^^^^^^   ^^^
                                 ?       ?         ?        ?

You want:

function resetTrash($host, $user, $password, $db){

PHP can warn you about this errors. Please read about error reporting.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top