2016-03-03 53 views
0

我改變MySQL的代碼在項目中的mysqli,但現在我得到的消息,儘管所有數據庫的信息就在這裏「沒有選擇的數據庫」是代碼:沒有數據庫中選擇mysqli的消息

<?php 

define('DB_SERVER', 'localhost'); 
define('DB_USERNAME', 'root'); // Your database Username 
define('DB_PASSWORD', 'root'); // Your database Password 
define('DB_DATABASE', 'social'); // Your database Name  
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysqli_error()); 
$database = mysqli_select_db($connection,DB_DATABASE) or die(mysqli_error()); 
mysqli_query($connection,$database); 

mysqli_query($connection,"SET NAMES 'UTF8'"); 
mysqli_query($connection,"SET character_set_connection = 'UTF8'"); 
mysqli_query($connection,"SET character_set_client = 'UTF8'"); 
mysqli_query($connection,"SET character_set_results = 'UTF8'"); 
$path = "uploads/"; 
$LogoPaht="css/icons/"; 
$conversation_uploads = "conversation_images/"; 
$profile_image_path = "user_profile_uploads/"; 
$admin_path = "../".$LogoPaht; 
$admin_profile_path='../'.$profile_image_path; 
$admin_path_uploads='../'.$path; 
$profile_cover_pic_path = "user_profile_cover_uploads/"; // User Profile Cover File 
$perpage=10; // Updates perpage 
$base_url='http://localhost/sociall/'; // base_url 
$admin_base_url=$base_url.'smadmin/'; // Admin base_url 
$gravatar=0; // 0 false 1 true gravatar image 
$rowsPerPage=1000000; //friends list 
$profilePerPage=3; 

/*SMTP Details */ 
$smtpUsername='[email protected]'; //[email protected] or you can use your webmail like [email protected] 
$smtpPassword='pass'; //gmail password or your webmail password 
$smtpHost='ssl://mail.yourwebsitename.com'; //tls://smtp.gmail.com if yo 
$smtpPort='465'; //465 
$smtpFrom='[email protected]'; //[email protected]} 
?> 
+2

'mysqli_query($ connection,$ database)'應該做什麼? '$ database'是一個布爾值,而不是SQL查詢字符串。 – Barmar

+1

僅供參考,您可以將數據庫指定爲'mysqli_connect'的第四個參數,您不需要單獨調用'mysqli_select_db'。 – Barmar

+0

mysqli_ *函數沒有與mysql_ *函數相同的API。請檢查手冊並更新功能 – codisfy

回答

0

刪除線:

$database = mysqli_select_db($connection,DB_DATABASE) or die(mysqli_error()); 
mysqli_query($connection,$database); 

通過改變你的代碼,這種添加數據庫名稱,以您的連接建立請求

如果您的連接失敗,可能是因爲您的mysql設置了端口訪問而不是套接字訪問。該數據庫行更改爲測試:

define('DB_SERVER', '127.0.0.1'); 

如果失敗你確信你使用一個插座,保持它localhost並驗證你的用戶具有本地主機的權限MySQL數據庫。

+0

我將我的代碼更改爲您的代碼,但仍然相同 –

+0

@HeshamAbusaif具體查詢' mysqli_query($連接,「....」);'你看到的Mysql錯誤的結果? – Ray

+0

有沒有mysqli錯誤,我剛剛收到一條消息,我認爲所有查詢完成,但我不知道爲什麼我收到此消息「沒有數據庫seelcted」 –