diff options
author | Christian Schneider | 2019-09-11 16:34:07 +0200 |
---|---|---|
committer | Christian Schneider | 2019-09-11 16:34:07 +0200 |
commit | d4d06851645ec2b8558c677ac28cf0c859d93890 (patch) | |
tree | 4ec3fa7667df71157565d77050473c2cd792a3a8 /it_dbi.class | |
parent | e91007ce1623a25818fc6545662caad683bf696b (diff) | |
download | itools-d4d06851645ec2b8558c677ac28cf0c859d93890.tar.gz itools-d4d06851645ec2b8558c677ac28cf0c859d93890.tar.bz2 itools-d4d06851645ec2b8558c677ac28cf0c859d93890.zip |
Fix auto_increment keys where warnings clobber insert_id
Diffstat (limited to 'it_dbi.class')
-rw-r--r-- | it_dbi.class | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/it_dbi.class b/it_dbi.class index 3c414f0..45a321d 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -50,6 +50,7 @@ class it_dbi var $_link; # DB link identifier (private) var $_dbid; # string identifying db connection. used for _state_purgeshared from outside var $_affectedrows;# Affected rows (mysql_affected_rows() gets clobbered) + var $_insertid; # Last inserted id (mysqli_insert_id() gets clobbered) var $_writes; # Number of (non-omittable) writes to sql using this instance @@ -561,6 +562,7 @@ function query($query, $p = array()) } $this->_affectedrows = $this->_link->affected_rows; # get_warnings() clobbers this + $this->_insertid = mysqli_insert_id($this->_link); # get_warnings() clobbers this if (($warning = $this->_link->get_warnings())) { do { @@ -763,7 +765,7 @@ function insert($tags = array(), $command = "INSERT") if ($result = $this->query($query = "$command INTO {$this->_p['table']} " . $set)) { - $id = ($this->_p['autoincrement'] && !isset($tags[$this->_p['keyfield']])) ? mysqli_insert_id($this->_link) : $tags[$this->_p['keyfield']]; + $id = ($this->_p['autoincrement'] && !isset($tags[$this->_p['keyfield']])) ? $this->_insertid : $tags[$this->_p['keyfield']]; if ($this->_p['keyfield'] && !$this->read($id) && $this->_p['safety']) $this->_fatal("insert(): can't read record back (key truncated?), id=\"$id\"", $query); |