我有一个Android应用程序我正在尝试连接到webhost。我收到以下2个.php文件的错误。
connect_db.php
<?php
function
connecting_db($connect )
{
$address= "localhost";
//$username = "root";
//$password = "";
$username = "my_user";
$password = "my_pass";
$db="my_datab";
if( ! $connect = mysqli_connect($address, $username, $password, $db))
echo "Problem in connecting database";
return $connect;
}
?>
出现空白屏幕。 然后,
get_vehicle.php
<?php
include_once "connect_db.php";
$connect = null;
$connect = connecting_db($connect);
$arr = array();
if(isset($_GET['user_id']))
{
$user_id = $_GET['user_id'];
$query = "select * from vehicle where user_id =".$user_id;
$result = mysqli_query($connect , $query);
while($data = mysqli_fetch_array($result, MYSQL_ASSOC))
{
array_push($arr, array("vehicle_id"=>$data['id'],
"name"=>$data['name'] , "year"=>$data['year'],"fuel_unit"=>$data['fuel_unit']));
}
echo json_encode(array("vehicles"=>$arr));
}
mysqli_close($connect);
?>
以下是出现的错误:
Warning: mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /srv/disk10/2102259/www/vehicletransp.me.pn/connect_db.php on line 18
Problem in connecting database
Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /srv/disk10/2102259/www/vehicletransp.me.pn/get_vehicle.php on line 28
Line 18: if(!$connect = mysqli_connect($address, $username, $password, $db))
Line 28: mysqli_close($connect);
请帮忙。 谢谢!