$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