我在通過本地主機上的PHP腳本選擇我的數據庫時遇到問題。數據庫選擇失敗。未知數據庫錯誤phpmyAdmin
我100%確信數據庫名稱拼寫正確,並且INFACT它出現在phpMyAdmin的非常好,只有當我試圖通過運行在本地主機的PHP腳本,它會顯示以下錯誤連接到它:
Database selection failed Unknown database 'fokrul_justdeals'
我的PHP代碼是在這裏:
<?php
class database{
public $connection;
// the user for the database
public $user = 'root';
// the pass for the user
public $pswd = '';
// the db from where you want to parse the info
public $db = 'fokrul_justdeals';
// the host where db is located
public $host = 'localhost';
function __construct(){
$this->connect();
}
private function connect(){
$this->connection = mysql_connect("$host", "$user", "$pswd") or die("Database connection failed ". mysql_error());
if($this->connection){
// we select the db that we want to work with
mysql_select_db($this->db, $this->connection) or die("Database selection failed " . mysql_error());
}
}
我看過成千上萬的論壇,我做的一切,我應。但不知道這裏出了什麼問題?
有趣的是,在所有數據庫中,只有在PHP腳本中將db名稱更改爲'mysql'時,系統纔會生成db'mysql'連接。
我試着創建不同的數據庫名稱,並嘗試創建新用戶並向他們添加完整權限。什麼都沒有爲我工作:(
不要使用mysql,使用的mysqli或PDO,它棄用 – Sam 2013-03-01 21:20:55
它仍然顯示數據庫選擇失敗。爲什麼它不與工作mysql_connect? – 2013-03-01 21:31:43
你可以通過任何其他方法(如MySQL Workbench或命令行)連接到數據庫? – Voitcus 2013-03-01 21:33:57