【问题标题】:Connection database using PHP 7 Error使用 PHP 7 错误连接数据库
【发布时间】:2016-08-20 19:43:55
【问题描述】:

你好,我正在试镜一个php 7的服务器,脚本在以前的版本中运行,不知道是否正确,似乎没有找到和查询数据库,谁能帮助我?

致命错误:未捕获错误:调用 /home/insert/public_html/classesBD.php:7 中未定义的函数 mysqli_connect() 堆栈跟踪:#0 /home/insert/public_html/classesBD.php(30):conecta- >conecta() #1 /home/insert/public_html/index.php(9):consultar->executa('SELECT * FROM p...') #2 {main} 抛出 /home/insert/public_html/classesBD .php 在第 7 行

第 7 行 -->

$this->bancoDados = mysqli_connect(SERVIDOR_BD, USUARIO_BD, SENHA_BD) or trigger_error(mysqli_error(),E_USER_ERROR);//3. Store in class variable

脚本

define("SERVIDOR_BD", "localhost");
define("BANCO_DE_DADOS", "XXXXXX");
define("USUARIO_BD", "XXXXXXXX");
define("SENHA_BD", "XXXXXXX");

class conecta {
    public $database_bancoDados = null;//1. New Added Field
    public $bancoDados = null;//2. New Added Field
    function conecta($servidor="", $bancoDeDados="", $usuario="", $senha=""){
        if (($servidor == "") && ($usuario == "") && ($senha == "") && ($bancoDeDados == "")){
            $this->bancoDados = mysqli_connect(SERVIDOR_BD, USUARIO_BD, SENHA_BD) or trigger_error(mysqli_error(),E_USER_ERROR);//3. Store in class variable
            $this->database_bancoDados = BANCO_DE_DADOS;//4. Store in class variable
        } else {
            $this->bancoDados = mysqli_connect($servidor, $usuario, $senha) or trigger_error(mysqli_error(),E_USER_ERROR);//5. Store in class variable
            $this->database_bancoDados = $bancoDeDados;//6. Store in class variable
        }
    }    
}

class consultar {

    var $bd;
    var $res;
    var $row;
    var $nrw;
    var $data;

    function executa($sql=""){
        if($sql==""){
            $this->res =  0; // Pointer result of the executed query
            $this->nrw =  0; // Line number the query returned, cruise control
            $this->row = -1; // Array of the current query line
        }
        // Connects to the database   
           $this->bd = new conecta();//7. Store in class variable
           $this->bd->conecta();//8. Store in class variable
           mysqli_select_db($this->bd->bancoDados, BANCO_DE_DADOS);//9. Change Here For parameter sequence
           $this->res = mysqli_query($this->bd->bancoDados, $sql); //10. Change here for parameter sequence
           $this->nrw = @mysqli_num_rows($this->res);

        $this->row = 0;
        if($this->nrw > 0)
            $this->dados();
    }

    function primeiro(){
        $this->row = 0;
        $this->dados();
    }

    function proximo(){
        $this->row = ($this->row<($this->nrw - 1)) ?
                        ++$this->row:($this->nrw - 1);
        $this->dados();
    }

    function anterior(){
        $this->row = ($this->row > 0) ? -- $this->row:0;
        $this->dados();
    }        

    function ultimo(){
        $this->row = $this->nrw-1;
        $this->dados();
    }

    function navega($linha){
        if($linha>=0 AND $linha<$this->nrw){
            $this->row = $linha;
            $this->dados();
        }
    }

    function dados(){
        mysqli_data_seek($this->res, $this->row);
        $this->data = mysqli_fetch_array($this->res);
    }
}
//Mostra todos os erros!    
error_reporting(E_ALL);
ini_set('display_errors', 1);

【问题讨论】:

  • 你确定你安装了mysqli扩展吗?
  • 您确定启用了mysqli 扩展吗?
  • 我会检查我会确保它已安装

标签: php mysql


【解决方案1】:

检查你的扩展!

<?php phpinfo();

或者如果你使用 cli: php -m

【讨论】:

  • 好吧,现在还有其他错误 :-) allow_url_fopen 和 curl 在此 PHP 配置中不可用 注意:未定义变量:第 18 行 /home/insert/public_html/logout.php 中的 _SESSION警告:session_destroy ():试图在第 20 行的 /home/insert/public_html/logout.php 中销毁未初始化的会话警告:无法修改标头信息 - 标头已由(输出开始于 /home/insert/public_html/logout. php:18) 在第 26 行的 /home/insert/public_html/logout.php 中仍然有人可以帮助我吗?
  • 首先,添加 session_start();到您的第一个脚本的第一行。不要在此函数之前添加 html 或任何标头函数。你可以从这里作弊:php.net/manual/en/function.session-start.php
猜你喜欢
  • 2016-08-13
  • 1970-01-01
  • 1970-01-01
  • 2015-04-23
  • 2016-06-11
  • 1970-01-01
  • 1970-01-01
  • 2012-05-15
相关资源
最近更新 更多