PHP mysqli_connect:当我的登录页面试图连接到数据库时,我遇到了这个错误
我是新来的sqli,PHP的改进版PHP mysqli_connect:当我的登录页面试图连接到数据库时,我遇到了这个错误,php,mysqli,Php,Mysqli,我是新来的sqli,PHP的改进版 <?php // Class for the transparent access of MySQL $con = mysqli_connect("host","database","port","user","passwd","conn","querytext","query_id","err","errno","record = array();","row = 0;","rows = 0;") or die ("Some error occur
<?php
// Class for the transparent access of MySQL
$con = mysqli_connect("host","database","port","user","passwd","conn","querytext","query_id","err","errno","record = array();","row = 0;","rows = 0;") or die ("Some error occured during connection " . mysqli_error($con));
function query($querystring) {
$this->querytext = $querystring;
$this->query_id = mysqli_query($this->querytext, $this->con);
$this->Errno = mysqli_errno($this->conn);
$this->Error = mysqli_error($this->conn);
if($this->query_id) {
if(strtolower(substr(trim($this->querytext),0,6)) == 'select'){
$this->rows = mysqli_num_rows($this->query_id);
} else {
$this->rows = 0;
}
$this->row = 0;
} else {
$this->rows = 0;
$this->row = 0;
$this->halt("Query failed!");
}
}
function setpassword($newpasswd){
$querystring = sprintf("SET PASSWORD = PASSWORD('%s')", $newpasswd1);
return $this->query($querystring);
}
function next_record() {
if($this->row < $this->rows) {
$this->record = mysql_fetch_array($this->query_id);
$this->Errno = mysql_errno($this->conn);
$this->Error = mysql_error($this->conn);
$this->row +=1;
$status = is_array($this->record);
} else {
$status = FALSE;
}
return $status;
}
function seek($pos) {
if(($pos >= 0 && $pos < $this->rows) &&
mysql_data_seek($this->query_id, $pos)) {
$this->Errno = mysql_errno($this->conn);
$this->Error = mysql_error($this->conn);
$this->row = $pos;
}
}
function close() {
$this->query = "";
$this->rows = 0;
$this->row = 0;
mysql_close($this->conn);
}
function htmltable () {
$resulttable='';
if($this->rows > 0){
$resulttable=sprintf("<table %s>", $tableoptions);
while($this->next_record()) {
/* Ueberschriften */
if($this->row == 1) {
$resulttable=$resulttable . "<tr>";
while(list($key, $value)=each($this->record)){
$resulttable=$resulttable . "<th>" . $key . "</th>";
}
$resulttable=$resulttable . "</tr>\n";
reset($this->record);
} /* Ende Ueberschriften */
$resulttable=$resulttable . "<tr>";
while(list($key, $value)=each($this->record)){
$resulttable=$resulttable . "<td>" . $value . "</td>";
}
$resulttable=$resulttable . "</tr>\n";
}
$resulttable=$resulttable . "</table>\n";
}
return $resulttable;
}
?>
您应该使用PDO连接到数据库,因为它更安全: 下面这些教程非常好:
另外,请确保您的数据库凭据位于一个单独的文件中,该文件包含在您用于连接数据库的文件中。错误消息是什么?天哪,mysqli_connect是否接受了那么多参数?哈哈$this->query\u id=mysqli\u query$this->querytext$this->con;这绝对是失败的。在mysqli中,连接是第一位的,而不是第二位。这里的错误太多了。最好你回去和RTM的。@Dwza可怕,你会是正确的-谢谢我正在检查turorials@goerge。我可以请助手帮我查询函数。我需要有关查询函数的帮助。我还没有很好地定义我的代码