当我尝试连接到我的数据库时,我收到以下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);
}
&GT;`
这是来自第二个函数的行43
:
$connection=mysqli_connect($host , $user , $password , $db);
我的主机MediaTemple
说他们可以使用我的连接信息从他们身边连接得很好,但是套接字错误似乎与MySQL
而不是我的代码有关。
我可以使用phpMyAdmin
等登录数据库。
答案 0 :(得分:0)
您只是忘记了功能参数:
function resetTrash(){
$connection=mysqli_connect($host , $user , $password , $db);
^^^^^ ^^^^^ ^^^^^^^^^ ^^^
? ? ? ?
你想:
function resetTrash($host, $user, $password, $db){
PHP可以警告您这些错误。请阅读error reporting。