2014-11-24 30 views
-2

我想知道如果任何人都可以帮我这个改变MySQL数据库连接,而不是库MySQLi请DATABSE连接功能变化MYSQL

public function __construct() { 
    $this->dbConnection = new mysqli($this->_dbHost, $this->_dbUsername, 
     $this->_dbPassword, $this->_databaseName); 

    if ($this->dbConnection->connect_error) { 
     die('Connection error.'); 
    } 
    } 

它的教程的一部分,但我之前和着还没有使用的mysqli解决这个问题以满足我的需求。

干杯 强尼

+0

但为什么要使用没有支持和不推荐使用的mysql? – MixedVeg 2014-11-24 07:09:34

+0

@MixedVeg你让我失望了吗? – jonnypixel 2014-11-25 04:11:19

+0

Nopes只是问你一些事情:P – MixedVeg 2014-11-25 04:26:09

回答

0

我不建议你使用mysql_ *功能,因为他们已经在PHP的新版本被弃用。您应该使用mysqli或PDO来消除不需要的通知。

<?php 
public function __construct() { 
    $this->dbConnection = mysql_connect($this->_dbHost,$this->_dbUsername,$this->_dbPassword); 

    if (!$this->dbConnection) { 
     die('Connection error.'); 
    } else { 
     $db = mysql_select_db($this->databaseName, $this->dbConnection) OR die("database could not select" .mysql_error()); 
    } 
} 
?> 
+0

感谢manish,但wheres数据库名称连接? – jonnypixel 2014-11-24 07:12:41

+0

我编辑了答案。 – 2014-11-24 07:15:51

+0

Thnaks Manish,但即时通讯仍然收到数据库无法选择无数据库选择 – jonnypixel 2014-11-24 07:19:41