Вопрос

  $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