关于return的返回的问题

peixin229 peixin229 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
function db_connect() {
$result = new mysqli('localhost', 'bm_user', 'password', 'bookmarks');
if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}


function register($username, $email, $password) {
// register new person with db
// return true or error message

// connect to db
$conn = db_connect();

// check if username is unique
$result = $conn->query("select * from user where username='".$username."'");
if (!$result) {
throw new Exception('Could not execute query');
}

if ($result->num_rows>0) {
throw new Exception('That username is taken - go back and choose another one.');
}

// if ok, put in db
$result = $conn->query("insert into user values
('".$username."', sha1('".$password."'), '".$email."')");
if (!$result) {
throw new Exception('Could not register you in database - please try again later.');
}

return true;
}

请问各位高手,第二个函数register($username, $email, $password)中的变量$result和第一个函数中return的$result是不是同一个。如果不是,那第一个函数return是不是仅仅返回$result的值,而不是变量return?
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
peixin229
基础编程 21,889 成员 140,329 内容