如何在面向对象php内部函数中使用where条件

如何在面向对象php内部函数中使用where条件,php,Php,我是我的函数无法在我的函数中使用where条件,当我想像这样更新适当的用户id:where user_id= 看看我的功能: 他的方式与我调用createProfile函数以允许更新的方式相同 因为您有五个占位符?=您应该传递5个参数来绑定参数。简单的方法是将$user_id作为参数传递: public function createProfile($profile_picture, $username,$businessname, $town, $user_id) { // user_id

我是我的函数无法在我的函数中使用where条件,当我想像这样更新适当的用户id:where user_id=

看看我的功能:

他的方式与我调用createProfile函数以允许更新的方式相同


因为您有五个占位符?=您应该传递5个参数来绑定参数。简单的方法是将$user_id作为参数传递:

public function createProfile($profile_picture, $username,$businessname, $town, $user_id) {  // user_id is a five parameter here
    $stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where user_id= ?");
    // I suppose user_id has is `integer` type
    $stmt->bind_param("ssssi",$profile_picture, $username, $businessname, $town, $user_id);

    $stmt->execute();
}
由于我们不知道您的类中有什么-在我的示例中,可能user id位于名为user_id的类属性中的某个位置,那么您可以这样使用它:

public function createProfile($profile_picture, $username,$businessname, $town) {  // NO user_id passed
    $stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where user_id= ?");
    // I suppose user_id has is `integer` type
    $stmt->bind_param("ssssi",$profile_picture, $username, $businessname, $town, $this->user_id);

    $stmt->execute();
}

那么,这个用户id将是第五个参数。你只交了四个。为什么?请停止错误标记您的问题,它们与CakePHP框架无关。我做了,我没有更改我的表格行,您做了什么?您是否检查了您传递的用户id?您检查错误了吗?这就是我调用createProfile函数来更新profile_信息表的方式:$response=array;如果isset$U POST['profile_picture']&isset$U POST['username']&isset$U POST['businessname']&isset$U POST['town']&isset$U POST['user_id']!={$profile_picture=$_POST['profile_picture'];$username=$_POST['username'];$businessname=$_POST['businessname'];$user_id=$_POST['user_id'];$response=$db->createProfile$profile_picture,$username,$businessname,$town,$user_id;}id所做的没有错误,但没有给出任何更改:公共函数createProfile$profile\u picture、$username、$businessname、$town、$user\u id{$stmt=$this->conn->prepareUPDATE profile\u information set profile\u picture=?,username=?,businessname=?,town=?where user\u id=?;//我假设user\u id是整数类型$stmt->bind\u paramsssi,$profile\u picture,$username,$businessname,$town,$user\u id;$stmt->execute;}有错误吗?你真的有这样一个id的用户吗?你真的更改了任何用户数据吗?
public function createProfile($profile_picture, $username,$businessname, $town, $user_id) {  // user_id is a five parameter here
    $stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where user_id= ?");
    // I suppose user_id has is `integer` type
    $stmt->bind_param("ssssi",$profile_picture, $username, $businessname, $town, $user_id);

    $stmt->execute();
}
public function createProfile($profile_picture, $username,$businessname, $town) {  // NO user_id passed
    $stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where user_id= ?");
    // I suppose user_id has is `integer` type
    $stmt->bind_param("ssssi",$profile_picture, $username, $businessname, $town, $this->user_id);

    $stmt->execute();
}