当我尝试连接到我的数据库时,收到以下 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)
我的连接文件:
<?php
$host = 'internal-db.s144844.gridserver.com';
$user = 'db144844_db';
$password = '***********';
$db = 'db144844_db';
?>
函数文件:
`
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
正常登录数据库等等。
最佳答案
您只是忘记了函数参数:
function resetTrash(){
$connection=mysqli_connect($host , $user , $password , $db);
^^^^^ ^^^^^ ^^^^^^^^^ ^^^
? ? ? ?
你想要:
function resetTrash($host, $user, $password, $db){
PHP 可以警告您有关此错误的信息。请阅读 error reporting .
关于php - MySQLI通过socket连接本地服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23522941/