2012-10-03 3 views
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); 

어떻게 자동 증가 ID를 삽입 할 수 있습니까?mysql의 자동 증가 값 쿼리 삽입

답변

2

MySql 클래스의 구현 세부 정보를 잘 숨겼습니다.

경우
  • 당신이 에게 PDO를 사용하고, 당신은 당신이 mysql_insert_id() 보면, mysqli을 사용하는 경우 LastInsertId()
  • 좀보고 싶을 것이다; 경우
  • 당신은 MySQL의을 사용하고 있습니다 : 스위치를
+1

교활한 세 번째 점을! – nickhar

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

문서 여기 PDO 또는 mysqli에 : http://php.net/manual/en/pdo.lastinsertid.php

+0

이 함수는 명령이 예를 선택하면 오류가 발생합니까? 또는 null을 반환 하시겠습니까? –

+0

당신은 어떤 예외도 잡으려고 시도해야 할 것입니다. 예전의 링크에있는 예를보세요. – martinwnet