PHP警告:mysqli_select_db()期望参数1为mysqli

时间:2019-03-16 16:38:32

标签: php mysql

我收到此错误

  

H01215:PHP警告:mysqli_select_db()期望参数1为   给出的mysqli字符串

当我尝试从MYSQL更改为MYSQLI时,从我的网站上

,为什么我不见了。我将每个mysql_更改为mysqli_

// Do we have a valid database connection and have we selected a database?
public function databaseSelected()
{
    if(!$this->isConnected()) return false;
    $result = mysql_list_tables($this->name, $this->db);
    return is_resource($result);
}

public function connect()
{
    $this->db = @mysql_connect($this->host, $this->username, $this->password) or $this->notify('Failed connecting to the database with the supplied connection details. Please check the details are correct and your MySQL user has permissions to access this database.<br/><br/>(host: '.$this->host.', user: '.$this->username.', pass: ********)');
    if($this->db === false) return false;
    mysql_select_db($this->name, $this->db) or $this->notify();             if($this->isConnected())
    {
        mysql_set_charset('UTF-8', $this->db);
        $this->query("SET NAMES utf8"); 
    }

    return $this->isConnected();
}

2 个答案:

答案 0 :(得分:1)

mysqli_select_db期望第一个参数为import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.linear_model import LogisticRegression # read data data = pd.read_csv('ex2data1.txt', header=None) X = data[[0,1]].values y = data[2] # use LogisticRegression log_reg = LogisticRegression() log_reg.fit(X, y) # Coefficient of the features in the decision function. (from theta 1 to theta n) parameters = log_reg.coef_[0] # Intercept (a.k.a. bias) added to the decision function. (theta 0) parameter0 = log_reg.intercept_ # Plotting the decision boundary fig = plt.figure(figsize=(10,7)) x_values = [np.min(X[:, 1] -5 ), np.max(X[:, 1] +5 )] # calcul y values y_values = np.dot((-1./parameters[1]), (np.dot(parameters[0],x_values) + parameter0)) colors=['red' if l==0 else 'blue' for l in y] plt.scatter(X[:, 0], X[:, 1], label='Logistics regression', color=colors) plt.plot(x_values, y_values, label='Decision Boundary') plt.show() 对象。

您需要更改参数的顺序,以便第一个参数是mysqli对象。

mysqli

答案 1 :(得分:0)

我对您的代码的首次观察是,您的代码为mysql时出现mysqli错误

另一个观察结果是您错过了数据库连接的参数顺序。 mysql_select_db的参数顺序不同于mysqli_select_db 下面的示例:

对于mysql_select_db

mysql_select_db('db_name', $con);

对于mysqli_select_db

mysqli_select_db($con,"db_name");