gpt4 book ai didi

php - php 中的 mysql_affected_rows()

转载 作者:行者123 更新时间:2023-11-29 03:50:49 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

我有下一节课:

<?php
class DbHelper{
private $databaseURL;
private $databaseUName;
private $databasePWord;
private $databaseName;
private $nameOfDbWithWorkers;
private $connection;

function __construct($dbURL, $dbUserName, $dbPword, $dbName, $nameOfDbWithWorkers){
$this->databaseURL = $dbURL;
$this->databaseUName = $dbUserName;
$this->databasePWord = $dbPword;
$this->databaseName = $dbName;
$this->nameOfDbWithWorkers = $nameOfDbWithWorkers;
}

function setConnectionToDb(){
$this->connection = mysql_connect($this->databaseURL,$this->databaseUName,$this->databasePWord) OR DIE("can't connect to DB");
mysql_select_db($this->databaseName, $this->connection)or die ("Error while connecting to database");
}

function getUser($login, $pass){
echo "$login, $pass";
$query = "SELECT type FROM $this->nameOfDbWithWorkers WHERE login = '$login' and password = '$pass';";
$queryResult = $this->getDataFromDbByQuery($query);
if ((mysql_affected_rows($this->connection) == 1)){
$meta = mysql_fetch_assoc($queryResult);
if ($meta['type']=='admin'){
return 'admin';
}
if ($meta['type']=='user'){
return 'user';
}
else{
return 'nomatch';
}
}
else{
return 'nomatch';
}
}

function getDataFromDbByQuery($query){
$this->setConnectionToDb();
$result = mysql_query($query);
mysql_close($this->connection);
return $result;
}
}
?>

并调用它

$dbHelp = new DbHelper($dbURL, $dbUName, $dbPword, $dbName, $nameOfDbWithWorkers);
$userType = $dbHelp->getUser($login, $pass);

还有下一个错误:

Warning: mysql_affected_rows(): 5 is not a valid MySQL-Link resource in Z:\home\ecl.ru\www\classes\dbhelper.php on line 27

怎么了?

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