普通网友 2016-08-20 19:43
浏览 24

使用PHP 7错误的连接数据库

Hello I'm auditioning for a server with php 7 have the script running in the previous version, do not know correct, it seems that is not finding and querying the database, could anyone help me?

Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /home/insert/public_html/classesBD.php:7 Stack trace: #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} thrown in /home/insert/public_html/classesBD.php on line 7

LINE 7 -->

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

the script

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);
  • 写回答

1条回答 默认 最新

  • duandu1966 2016-08-20 20:54
    关注

    Check your extensions!

    <?php phpinfo();
    

    or if you use cli: php -m

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP