php pdo success but dont enter the data to the database

I have this weird issue with my PDO/SQL. I use namespaces and classes to control things.

I use a custom PDO class which is because I also define some standard values like PDO should throw exceptions and so.

The weird issue appears when I try to create a user. I'm in the development stage on this project thereby I'm hardcoding a test login.

try  
{  
$user = new OOP\User\user();  
$user->setFirstname("Firstname");  
$user->setLastname("Lastname");  
$user->setUsername("Test");  
$user->setSecret(OOP\utillityClass::create_unique_hash(128));  
$user->setPassword(OOP\utillityClass::create_password("*Duh as if im studpid enought to post my password*", $user->getSecret()));  
$user->setEmail("some mail");  
$birthday = new DateTime("1990-01-01");  
$user->setBirthday($birthday);  
$user->setClass(1);  
$user->setAdded(new DateTime());  
$user->setLast_Active(new DateTime());  
$user->setActivated(true);  
$user->setIp(OOP\utillityClass::getip());  
$user->setIv(OOP\Crypt\crypt::createIv("hex"));  
$permissions = array();  
$permissions['staff'] = array();  
$permissions['staff']['read'] = 1;  
$user->setPermissions(json_encode($permissions));  
$user->save();  
}  
catch (Exception $e)  
{  
echo "Error *censored, i use slurs while debugging*:" . PHP_EOL;  
print_r($e);  
}

The above is the creation code.

This is the table in the database:

CREATE TABLE IF NOT EXISTS `user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `firstname` varchar(50) NOT NULL,
  `lastname` varchar(50) NOT NULL,
  `username` varchar(50) NOT NULL,
  `password` varchar(128) NOT NULL,
  `secret` varchar(128) NOT NULL,
  `email` varchar(255) NOT NULL,
  `birthday` date NOT NULL,
  `class` int(11) NOT NULL,
  `added` datetime NOT NULL,
  `last_active` datetime NOT NULL,
  `activated` tinyint(1) NOT NULL DEFAULT '0',
  `ip` varchar(40) NOT NULL,
  `iv` varchar(32) NOT NULL,
  `permissions` text NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;

And here comes the insert code (note that it is the public save method that is called, but the save method call this private method since there is no user loaded, then it creates it):

private function insert()
{

    // We need the $CONFIG variable for sending actiovation emails \\
    global $CONFIG;

    $q = $this->PDO->prepare("INSERT INTO `user` (`firstname`, `lastname`, `username`, `password`, `secret`, `email`, `birthday`, `class`, `added`, `last_active`, `activated`, `ip`, `iv`, `permissions`) VALUES (:firstname, :lastname, :username, :password, :secret, :email, :birthday, :class, :added, :last_active, :activated, :ip, :iv, :permissions);");


    $q->bindParam(':firstname', $this->firstname);
    $q->bindParam(':lastname', $this->lastname);
    $q->bindParam(':username', $this->username);
    $q->bindParam(':password', $this->password);
    $q->bindParam(':secret', $this->secret);
    $q->bindParam(':email', $this->email);
    $q->bindParam(':birthday', $this->birthday->format("Y-m-d"));
    $q->bindParam(':class', $this->class);
    $q->bindParam(':added', $this->added->format("Y-m-d H:i:s"));
    $q->bindParam(':last_active', $this->last_active->format("Y-m-d H:i:s"));
    $q->bindParam(':activated', $this->activated);
    $q->bindParam(':ip', $this->ip);
    $q->bindParam(':iv', $this->iv);
    $q->bindParam(':permissions', $this->permissions);

    $res = $q->execute();

    if ($q->errorCode() != 00000)
    {
        throw new \Exception("An error occured during the creation");
    }
    else
    {
        return true;
    }

}

Now here comes the fun thing, there is no Exception or PDOException's at all, actually it passes as it should but it does not enter the data into the database, but the auto increment number increase by 1.

I really hope someone can help me out with this one since I've been trying to get this to work all day long, and I've tried to drop and recreate the database and tables, including the insert code.

On beforehand, thank you very much for your time and help.

Answers


Try viewing the return value of the errorInfo function like so var_dump($q->errorInfo());. This gives you the error message if you really have failed in executing the query the same as if you have executed that query in an actual client tool (i.e. MySQL Workbench) of the DBMS.


Need Your Help

jqueryui autocomplete: lists entries with search terms in middle

jquery-ui autocomplete prefix

I am using jqueryui autocomplete widget for autocompleting a 'country' field but I am facing an issue. Suppose the user enters "in", I want the jqueryui to list countries like 'india', 'indonesia' ...

Java (Windows-only issue): alwaysOnTop JFrame falls to bottom of z-order when modal dialog is popped and blocked JFrames are clicked

java swing jdialog z-order modality

I have a Java application whose basic UI consists of two JFrames: a client area, and a tool palette which should always appear above the client area. To achieve this, the tool palette is set to