0
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?

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

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

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

2 Comments

is this function raise an error if the command is select for example? or return null?
You would have to try/catch any exceptions, see examples in my previous link (in the comments).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.