duanhui1869 2016-10-15 18:24
浏览 26

类mysql试图将其转换为mysql实例

I have a mysqli class, previously converted from the mysql extension. But now I get this error:

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\AppServ\www\ADMIN2\i_n_c\db.php on line 27

Database error: cannot use database test1n

MySQL Error: 0 ()nSession halted.

I used this class with mysql_* for many years but now I am trying to figure it with MySQLi.

<?php
class Database
{
    var $Host     = "localhost"; // Hostname of our MySQL server.
    var $Database = "test1"; // Logical database name on that server.
    var $User     = "root"; // User and Password for login.
    var $Password = "123456789";

    var $Link_ID  = 0;  // Result of mysql_connect().
    var $Query_ID = 0;  // Result of most recent mysql_query().
    var $Record   = array();  // current mysql_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 );
        } // end function connect

//-------------------------------------------
//    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;
        } // end function query

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

//-------------------------------------------
//    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;
        } // end function nextRecord

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

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

    } // end class Database
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行