0

Its weird, the below code used to work nicely. After running the same code, it runs but doesn't make any entry into the database. Username, password , database name , etc are all correct and PDO extension is present and enabled in php(as I checked in phpinfo).Even checked privileges in phpmyadmin, root on localhost got ALL PRIVILEGES.Code always returns false with no warning , notice or error. What possibly can be the reason??

Code for registration of new user:

$randomSalt = base64_encode(mcrypt_create_iv(PBKDF2_SALT_BYTE_SIZE, MCRYPT_DEV_URANDOM));
        $saltedPass = base64_encode($this->pbkdf2(PBKDF2_HASH_ALGORITHM,
                        $password,
                        $randomSalt,
                        PBKDF2_ITERATIONS,
                        PBKDF2_HASH_BYTE_SIZE,
                        true
                    ));

        $id = $this->NewGuid();

        $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`id`, `username`, `password`, `password_salt`, `created`) VALUES(:id, :username, :password, :passwordSalt, NOW())");
        /* Bind the default values */
        $sql->bindValue(":id", $id);
        $sql->bindValue(":username", $mail);
        $sql->bindValue(":password", $saltedPass);
        $sql->bindValue(":passwordSalt", $randomSalt);
        //$sql->bindValue(":created", UNIX_TIMESTAMP(now()));
        if($sql->execute())
        {
            $_SESSION['logSyscuruser'] = $id;
            setcookie("logSyslogin", hash("sha256", $this->secureKey.$id.$this->secureKey), time()+3600*99*500, "/");

            return true;
        }
        else
        {
            return false;
        }
  • 2
    Do you have warning and errors messages turned on in PHP? – Spencer Wieczorek Oct 14 '15 at 16:17
  • At some point above this code block, are you initializing the `PDO` object (i.e. `$this->dbh = new PDO(...);`... – War10ck Oct 14 '15 at 16:18
  • ...and since you have no explicit error handler in this code snippet: have you set the error mode to [PDO::ERRMODE_EXCEPTION](http://docs.php.net/manual/en/pdo.constants.php#pdo.constants.errmode-exception)? – VolkerK Oct 14 '15 at 16:20
  • yes i have warning and error messages turned on.. – milan kumar Oct 14 '15 at 16:21
  • $this->dbh = new PDO("mysql:dbname={$this->dbname};host={$this->dbhost};port={$this->dbport}", $this->dbuser, $this->dbpass); – milan kumar Oct 14 '15 at 16:21

1 Answers1

-2

In my case happened due to memory limit issue. My code was working on localhost but was not working on live server. I increased the memory limit and all works perfectly.

Add below code in your php.ini file and upload it on root.

memory_limit= -1;

Hope this help you.

  • 1
    This is a really bad suggestion. First, you have no reason at all from information posted to think that this has any chance of solving this problem. We don't even have a single bit of error information provided by OP. Second, following your suggestion would open up the PHP environment to be able to have a runaway process basically lock up your server because PHP no longer throttles memory usage. If you have memory problems with an application, you should determine root cause and fix it, not allow your problem to potentially take down the server because instead of fixing you remove constraint – Mike Brant Oct 14 '15 at 17:50