X-Git-Url: https://dev.renevier.net/?p=syp.git;a=blobdiff_plain;f=inc%2Fdb%2Fmysql.php;h=8c07aa3de81c304922b7376d6d266ef13b9ca2c8;hp=8e6253fc6e0f5fbae1cfb40ab29107757a7d9f9d;hb=939514b912738c5784b04a0d207db1afd918eb69;hpb=3c74920cb66b4e6c47c7e8a0eaeed40ffb7e8544 diff --git a/inc/db/mysql.php b/inc/db/mysql.php index 8e6253f..8c07aa3 100644 --- a/inc/db/mysql.php +++ b/inc/db/mysql.php @@ -54,18 +54,19 @@ class mysqlConnection implements anydbConnection { $this->_execute_query ($query); } - public function setpwd ($user_name, $pwd, $create_if_not_exists) { + public function user_exists ($user_name) { $usrname_escaped = mysql_real_escape_string ($user_name); $query = sprintf ("SELECT COUNT(*) FROM %susers WHERE name LIKE '%s';", $this->dbprefix, $usrname_escaped); $res = mysql_fetch_array ($this->_execute_query ($query), MYSQL_NUM); - if ($res [0] == 1) { - if ($create_if_not_exists) { - $query = sprintf ("UPDATE %susers SET pwd='%s' WHERE name like '%s';", - $this->dbprefix, md5 ($pwd), $usrname_escaped); - } else { - throw new Exception (anydbConnection::err_query); - } + return ($res [0] == 1); + } + + public function setpwd ($user_name, $pwd) { + $usrname_escaped = mysql_real_escape_string ($user_name); + if ($this->user_exists ($user_name)) { + $query = sprintf ("UPDATE %susers SET pwd='%s' WHERE name like '%s';", + $this->dbprefix, md5 ($pwd), $usrname_escaped); } else { $query = sprintf ("INSERT INTO %susers VALUES ('%s', '%s');", $this->dbprefix, $usrname_escaped, md5 ($pwd));