Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数据库错误:无法使用数据库mydatabase MySQL错误:0()会话已暂停_Php_Mysql_Mysqli_Mariadb - Fatal编程技术网

Php 数据库错误:无法使用数据库mydatabase MySQL错误:0()会话已暂停

Php 数据库错误:无法使用数据库mydatabase MySQL错误:0()会话已暂停,php,mysql,mysqli,mariadb,Php,Mysql,Mysqli,Mariadb,我刚刚从一个论坛下载了一些代码,但是这些代码在mysql中运行得不好。它报告以下错误: 数据库错误:无法使用数据库mydatabase MySQL错误:0()会话已暂停。 我已经尝试在谷歌的错误日志中查找和修复了 代码如下: <?php class Database { var $Host = "127.0.0.1"; // Hostname of our MySQL server. var $Database = "mydatabase";

我刚刚从一个论坛下载了一些代码,但是这些代码在mysql中运行得不好。它报告以下错误:

数据库错误:无法使用数据库mydatabase MySQL错误:0()会话已暂停。

我已经尝试在谷歌的错误日志中查找和修复了

代码如下:

<?php

class Database
{
    var $Host     = "127.0.0.1";        // Hostname of our MySQL server.
    var $Database = "mydatabase";               // Logical database name on that server.
    var $User     = "root";                 // User and Password for login.
    var $Password = "mypassword";

    var $Link_ID  = 0;                  // Result of mysqli_connect().
    var $Query_ID = 0;                  // Result of most recent mysqli_query().
    var $Record   = array();            // current mysqli_fetch_array()-result.
    var $Row;                           // current row number.
    var $LoginError = "";

    var $Errno    = 0;                  // error state of query...
    var $Error    = "";

    //-------------------------------------------
    //    Connects to the database
    //-------------------------------------------
    function connect()
    {
        if( 0 == $this->Link_ID )
            $this->Link_ID=mysqli_connect( $this->Host, $this->User, $this->Password );
        if( !$this->Link_ID )
            $this->halt( "Link-ID == false, connect failed" );
        if( !mysqli_query( sprintf( "use %s", $this->Database ), $this->Link_ID ) )
            $this->halt( "cannot use database ".$this->Database );
    }

    //-------------------------------------------
    //    Queries the database
    //-------------------------------------------
    function query( $Query_String )
    {
        $this->connect();
        $this->Query_ID = mysqli_query( $Query_String,$this->Link_ID );
        $this->Row = 0;
        $this->Errno = mysqli_errno();
        $this->Error = mysqli_error();
        if( !$this->Query_ID )
            $this->halt( "Invalid SQL: ".$Query_String );
        return $this->Query_ID;
    }

    //-------------------------------------------
    //    If error, halts the program
    //-------------------------------------------
    function halt( $msg )
    {
        printf( "<strong>Database error:</strong> %s", $msg );
        printf( "<strong>MySQL Error</strong>: %s (%s)", $this->Errno, $this->Error );
        die( "Session halted." );
    }

    //-------------------------------------------
    //    Retrieves the next record in a recordset
    //-------------------------------------------
    function nextRecord()
    {
        @ $this->Record = mysqli_fetch_array( $this->Query_ID );
        $this->Row += 1;
        $this->Errno = mysqli_errno();
        $this->Error = mysqli_error();
        $stat = is_array( $this->Record );
        if( !$stat )
        {
            @ mysqli_free_result( $this->Query_ID );
            $this->Query_ID = 0;
        }
        return $stat;
    }

    //-------------------------------------------
    //    Retrieves a single record
    //-------------------------------------------
    function singleRecord()
    {
        $this->Record = mysqli_fetch_array( $this->Query_ID );
        $stat = is_array( $this->Record );
        return $stat;
    }

    //-------------------------------------------
    //    Returns the number of rows  in a recordset
    //-------------------------------------------
    function numRows()
    {
        return mysqli_num_rows( $this->Query_ID );
    }

    //-------------------------------------------
    //    Returns the Last Insert Id
    //-------------------------------------------
    function lastId()
    {
        return mysqli_insert_id();
    }

    //-------------------------------------------
    //    Returns Escaped string
    //-------------------------------------------
    function mysqli_escape_mimic($inp)
    {
        if(is_array($inp))
            return array_map(__METHOD__, $inp);
        if(!empty($inp) && is_string($inp))
        {
            return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp);
        }
        return $inp;
    }
    //-------------------------------------------
    //    Returns the number of rows  in a recordset
    //-------------------------------------------
    function affectedRows()
    {
        return mysqli_affected_rows();
    }

    //-------------------------------------------
    //    Returns the number of fields in a recordset
    //-------------------------------------------
    function numFields()
    {
        return mysqli_num_fields($this->Query_ID);
    }

}

?>

我已经尝试了针对堆栈溢出建议的其他方法。

来自

程序风格

mysqli\u查询(mysqli$link,string$query[,int$resultmode=mysqli\u STORE\u RESULT]):混合

参数

link:mysqli\u connect()返回的链接标识符 质疑

查询:查询字符串

您的代码无法工作,因为您将sql语句作为第一个参数传递,后跟连接句柄。请注意,您还可以将
mysqli\u connect
中的数据库指定为第四个参数。这将更快,因为默认数据库是在客户机-服务器握手期间设置的。

From

程序风格

mysqli\u查询(mysqli$link,string$query[,int$resultmode=mysqli\u STORE\u RESULT]):混合

参数

link:mysqli\u connect()返回的链接标识符 质疑

查询:查询字符串


您的代码无法工作,因为您将sql语句作为第一个参数传递,后跟连接句柄。请注意,您还可以将
mysqli\u connect
中的数据库指定为第四个参数。这会更快,因为默认数据库是在客户端-服务器握手期间设置的。

数据库
mydatabase
是否存在?读取并检查代码中的参数。这是错误消息。相反,让我们看看mysqli的错误信息。数据库mydatabase存在吗Darragh Enright 2天前=是这是您的错误消息。相反,让我们看看mysqli的错误信息Rick James昨天没有其他错误消息(日志)…数据库
mydatabase
是否存在?读取并检查代码中的参数。这是您的错误消息。相反,让我们看看mysqli的错误信息。数据库mydatabase存在吗Darragh Enright 2天前=是这是您的错误消息。相反,让我们看看mysqli的错误信息Rick James昨天没有其他错误消息(日志)。。