1

Hi I am getting error during the execution of PDO prepare statement. My local development works fine but when I try to insert to cleardb in cloud this error occur:

SQLSTATE[42000]: Syntax error or access violation: 1142 INSERT command denied to user 'b2218f51d4a66e'@'191.235.136.58' for table 'user'' in /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;
        }
    }
}
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
surajnew55
  • 573
  • 1
  • 11
  • 25

1 Answers1

0

This is a permissions problem. Your database user has the INSERT permission for the table on your development server but not on your production server, so you'll need to change the user permissions using GRANT on your production server.

GMemory
  • 137
  • 9
  • If so why does this query works fine from mysql workbench:INSERT INTO `as_754979fd4dcbfcb`.`user` (`userId`, `userName`, `passWord`, `create_DateStamp`, `update_DateStamp`, `e_mail`) VALUES (default, "1111", "2222", now(), default, "abc@123.com"); – surajnew55 Apr 23 '14 at 11:18
  • Are you logging in to Workbench as the user `b2218f51d4a66e`? Also, please bear in mind that the second part of the user identifier also counts (for example, 'b2218f51d4a66e'@'191.235.136.58' isn't the same as 'b2218f51d4a66e'@'%', the latter allowing access from any host as opposed to one single host) – GMemory Apr 24 '14 at 08:42