Alaa Joumaa
Alaa Joumaa

Reputation: 3

Auto-increment value from mysql Insert query

if(!class_exists('MySql'))
{ include('MySql.php'); }
  $sql=new MySql();
  $sql->connect();
  $sqlCommand="insert into `freecomputermarket`.`members`
 (`UserName`,`Password`,`Email`,`BirthDate`,`RegisterationDate`,`ActivationCode`,
 `ActivationLink`,`IsActive`,`Gender`)
 values('$this->_userName','$this->_password','$this->_email','$this->_birthDate',
 '$this->_registerationDate','$this->_activationCode','$this->_activationLink',
 '$this->_isActive','$this->_gender')";
  $sql->query($sqlCommand);

how i can get the Auto-increment ID inserted?

Upvotes: 0

Views: 632

Answers (2)

martinwnet
martinwnet

Reputation: 581

$sql->query($sqlCommand);
$id = lastInsertId();

Documentation here: http://php.net/manual/en/pdo.lastinsertid.php

Upvotes: 0

JvdBerg
JvdBerg

Reputation: 21866

You have hidden the implementation details of your MySql class very well.

  • In case you are using PDO, you will want to have a look at LastInsertId()
  • In case you are using mysqli, look at mysql_insert_id();
  • In case you are using mysql: switch to PDO or mysqli

Upvotes: 2

Related Questions