note 88303 deleted from pdo.lastinsertid by danbrown
| From: | danbrown@php.net | Date: | Mon, 19 Jan 2009 20:46:18 +0000 |
| Subject: | note 88303 deleted from pdo.lastinsertid by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-149482@lists.php.net to get a copy of this message | ||
Note Submitter: info at nospam dot timreeves dot de
----
Improvement to my previous post - the ID returned by MSSQL was assumed stringified (and still is,
this is PDO default) - but the string-cleanup assumed german locale formatting. The following
snippet (replacing about 6 lines towards the end of the previous fragment) makes it locale
independent:
<?php
$strLastRowId = trim($rowTd[0]); // trim() for trailing Nullbyte
// Integers are returned stringified, format depends on locale
// Generally ends with ",00" or ".00" - trim that off
$strLastRowId = preg_replace('/[,.]0+$/', '', $strLastRowId);
// Remove any remaining "." or "," for thousands
$strLastRowId = preg_replace('/[,.]/', '', $strLastRowId);
?>