Question

  $userName = $this->getParam('userName', self::TYPE_STRING); 

  $db = Frapi_Database::getInstance();
  $sql = "INSERT INTO user (userName)
            values ('".$userName."')";

  $stmt = $db->prepare($sql);        

  $stmt->execute();

  $this->data['userId'] = mysql_insert_id();

always getting 0 in userId.

i tried to search this, but couldn't find any solution for it.

Était-ce utile?

La solution 2

thanks for your help guyz.
this worked for me.
$this->data['userId'] = $db->lastInsertId();

Autres conseils

Have you read the documentation?

The ID generated for an AUTO_INCREMENT column by the previous query on success, 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established.

Also, these calls are deprecated.

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.

Read about choosing a new API here

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top