連接我剛剛創建的Android應用程序,其中應用程序通過PHP文件與MySQL連接..我就照這個教程thisAndroid應用程序與MySQL不工作
但我能夠連接時igave本地主機地址時我給它不工作我的服務器地址。以下是db_connect ..我沒有做任何改變
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>
db_config.php
<?php
/*
* All database connection variables
*/
define('DB_USER', "root");
// db user
define('DB_PASSWORD', "");
// db password (mention your db password here)
define('DB_DATABASE', "androidhive");
// database name
define('DB_SERVER', "localhost"); // db server
?>
this是我上傳我的文件的鏈接...
警告:mysql_connect()[function.mysql-connect]:無法通過套接字連接到本地MySQL服務器'/var/lib/mysql/mysql.sock '(2)in /home/content/96/11645896/html/app/db_connect.php on line 28 無法通過套接字'/var/lib/mysql/mysql.sock'連接到本地MySQL服務器(2) 警告:mysql_close():沒有在第42行的/home/content/96/11645896/html/app/db_connect.php中提供的MySQL-Link資源
但是消息是這樣的......我必須做的...
你有沒有運行mysqld? – Akshay
我們將如何知道..? – roshanpeter