mysql通过套接字错误连接到本地服务器


MySQLI connect to local server through socket error

当我尝试连接到我的DB时,我收到以下MySQLI错误:

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'; ?>

functions文件:

'

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

?> "

这是第二个函数的43行:

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

我的主机MediaTemple说他们可以使用我的连接信息从他们这边连接,但是套接字错误似乎与MySQL有关,而不是我的代码。

我可以使用phpMyAdmin等登录到DB。

你只是忘记了函数参数:

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

你想:

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

PHP可以警告你这个错误。