我正在努力改进我的功能包括我正在制作的网站的文件。下面的代码是函数include的摘录。我正试图让affected_rows检查查询是否已成功执行但没有运气。
<?php
function connect() {
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
. $mysqli->connect_error);
}
return $mysqli;
}
function insert($type, $values) {
$mysqli = connect();
if ( $type == 'newclient' ) {
$query = "INSERT INTO client_details (first_name, surname, email, password, dob, country, region, postcode, phone_main, phone_mobile, date_registered, regcode) values ( '{$_SESSION['first_name']}', '{$_SESSION['surname']}', '{$_SESSION['confirm_email']}', '$scrambledeggs', '{$_SESSION['dob']}', '{$_SESSION['country']}', '{$_SESSION['region']}', '{$_SESSION['postcode']}', '{$_SESSION['phone_main']}', '{$_SESSION['phone_mobile']}', NOW(), '$verification_hash')";
if ( !$mysqli->query($query) ) {
return "Errormessage: $mysqli->error";
}
}
}
我正在尝试获取受影响的行以确认查询已正确运行,但到目前为止我的尝试都没有用,这就是我尝试过的...
if ( !$mysqli->query($query) ) {
return "Errormessage: $mysqli->error";
}
if (($mysqli->affected_rows) > 0 ) {
($_SESSION['success'] = 1);
}