如何使用php检查更新是否完成
如何使用php检查所使用的查询是否更新我的表 下面是我的代码如何使用php检查更新是否完成,php,mysql,Php,Mysql,如何使用php检查所使用的查询是否更新我的表 下面是我的代码 $sql_query = "update companies set first_name = '$first_name', last_name = '$last_name', designation = '$designation', company_name = '$company_name', street_address = '$street_a
$sql_query = "update companies set
first_name = '$first_name',
last_name = '$last_name',
designation = '$designation',
company_name = '$company_name',
street_address = '$street_address',
city_code = '$city_code',
telephone_number = '$telephone_number',
mobile_number = '$mobile_number',
fax_number = '$fax_number'
where company_code='1001';";
if (!mysqli_query($conn_1,$sql_query) )
{
$_SESSION['error_details'][0] = 'no';
$_SESSION['error_details'][1] = 'Sorry, not update!';
}
else
{
$_SESSION['error_details'][0] = 'yes';
$_SESSION['error_details'][1] = 'Thank you, update sucessfully!';
}
如何在“如果条件”中检查此更新返回受上次插入、更新、替换或删除查询影响的行数
mysqli\u infected\u rows()
将返回受更新影响的行数
用于检查已更新的查询是否执行任何更新
if(mysqli_affected_rows($con) > 0) {
//update performed
}
如果您正在更新的数据与数据库中的数据不同,PHP只会更新,一个好的做法是使用类或orm,如果您更喜欢纯PHP,则使用类或函数小心您正在做的事情(小心错误将在开发时显示在ly上)
$result=mysql\u query($sqlString)或die(mysql\u eror());//然后你将确定没有错误;
if(mysql受影响的行($result)函数返回上一次SELECT、INSERT、UPDATE、REPLACE或DELETE查询中受影响的行数
更多信息:
如果($\u SESSION['error\u details'][0]='yes'){//update coursed}或者{//update not coursed}
?手册没有提到错误处理吗?
$result = mysql_query($sqlString) or die(mysql_eror()); // then you will be sure there is no errors;
if (mysql_affected_rows ($result) <= 0) {
//do as you need for no changes on your database
} else {
//do as you want on database changed
}
$conn_1 = mysqli_connect("localhost", "DB_USER", "DB_PASSWORD", "DB_NAME");
$sql_query = "update companies set
first_name = '$first_name',
last_name = '$last_name',
designation = '$designation',
company_name = '$company_name',
street_address = '$street_address',
city_code = '$city_code',
telephone_number = '$telephone_number',
mobile_number = '$mobile_number',
fax_number = '$fax_number'
where company_code='1001'";
mysqli_query($conn_1,$sql_query);
if (mysqli_affected_rows($conn_1))
{
$_SESSION['error_details'][0] = 'yes';
$_SESSION['error_details'][1] = 'Thank you, update sucessfully!';
}
else
{
$_SESSION['error_details'][0] = 'no';
$_SESSION['error_details'][1] = 'Sorry, not update!';
}