문제

  $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