質問

  $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.

役に立ちましたか?

解決 2

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

他のヒント

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top