gpt4 book ai didi

php - 数据库错误 : cannot use database mydatabase MySQL Error: 0 ()Session halted

转载 作者:行者123 更新时间:2023-11-30 21:26:23 27 4
gpt4 key购买 nike

<分区>

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

Database error: cannot use database mydatabase MySQL Error: 0 ()Session halted.

我已经尝试在错误日志中在google中查找并​​修复

下面是代码:

<?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);
}

}

?>

我已经尝试过 Stack Overflow 上建议的其他方法。

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com