PHP PDO执行和插入cleardb时出错

时间:2014-04-23 10:53:47

标签: php mysql pdo cleardb

您好,我在执行PDO准备语句时遇到错误。我的本地开发工作正常,但是当我尝试在云中插入cleardb时会发生以下错误:

  

SQLSTATE [42000]:语法错误或访问冲突:1142 INSERT命令被拒绝用户'b2218f51d4a66e'@'191.235.136.58'表'user''在/var/www/php1/CRUD.php:52

    function create_User($firstname, $lastname, $username, $password, $address, $city, $zip, $country, $email) {
    global $dbh;
    $this->password = $password;
    $token = md5($this->salt1 . $this->password . $this->salt2);

    $this->sth = $dbh->prepare('INSERT INTO `Php_Project`.`User`
(        
userName,
passWord,
    create_DateStamp,
e_mail)

    VALUES
    (               
            :username,
    :token,
            NOW(),
    :email
    );

“);

    $this->sth->bindParam(':username', $username, PDO::PARAM_STR);
    $this->sth->bindParam(':token', $token, PDO::PARAM_STR);
    $this->sth->bindParam(':email', $email, PDO::PARAM_STR);
    if ($this->sth->execute()) {
        $this->message = "true";
    } else {
        $this->message = "false";
    }

    if ($this->message == "true") {
        $userId = $dbh->lastInsertId();
        $this->sth = $dbh->prepare('INSERT INTO `Php_Project`.`user_Detail`
(    
firstName,
lastname,
adress,
zip,
city,
country,
userId)

    VALUES
    (       
        :firstname,
        :lastname,
        :address,
        :zip,
        :city,
        :country,
        :userId
    );');

        $this->sth->bindParam(':firstname', $firstname, PDO::PARAM_STR);
        $this->sth->bindParam(':lastname', $lastname, PDO::PARAM_STR);
        $this->sth->bindParam(':address', $address, PDO::PARAM_STR);
        $this->sth->bindParam(':zip', $zip, PDO::PARAM_INT);
        $this->sth->bindParam(':city', $city, PDO::PARAM_STR);
        $this->sth->bindParam(':country', $country, PDO::PARAM_STR);
        $this->sth->bindParam(':userId', $userId, PDO::PARAM_STR);
        if ($this->sth->execute()) {
            $this->message = true;
        } else {
            $this->message = false;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

这是权限问题。您的数据库用户对开发服务器上的表具有INSERT权限,但在生产服务器上没有,因此您需要使用生产服务器上的GRANT更改用户权限。