Make sure sql last insert id always returns integer
This commit is contained in:
parent
f1873d0410
commit
3e8e6b08c5
@ -114,7 +114,7 @@ require_once(ROOT_DIR . "/helpers/upload.php");
|
||||
$positionId = false;
|
||||
if (is_numeric($lat) && is_numeric($lon) && is_numeric($timestamp) && is_numeric($userId) && is_numeric($trackId)) {
|
||||
$track = new uTrack($trackId);
|
||||
if ($track->isValid && $track->userId == $userId) {
|
||||
if ($track->isValid && $track->userId === $userId) {
|
||||
try {
|
||||
$table = self::db()->table('positions');
|
||||
$query = "INSERT INTO $table
|
||||
@ -125,7 +125,7 @@ require_once(ROOT_DIR . "/helpers/upload.php");
|
||||
$params = [ $userId, $trackId,
|
||||
$timestamp, $lat, $lon, $altitude, $speed, $bearing, $accuracy, $provider, $comment, $image ];
|
||||
$stmt->execute($params);
|
||||
$positionId = self::db()->lastInsertId("${table}_id_seq");
|
||||
$positionId = (int) self::db()->lastInsertId("${table}_id_seq");
|
||||
} catch (PDOException $e) {
|
||||
// TODO: handle error
|
||||
syslog(LOG_ERR, $e->getMessage());
|
||||
@ -299,7 +299,7 @@ require_once(ROOT_DIR . "/helpers/upload.php");
|
||||
* @return bool True if success, false otherwise
|
||||
*/
|
||||
public static function removeImages($userId, $trackId = NULL) {
|
||||
if (($positions = uPosition::getAllWithImage($userId, $trackId)) !== false) {
|
||||
if (($positions = self::getAllWithImage($userId, $trackId)) !== false) {
|
||||
/** @var uUpload $position */
|
||||
foreach ($positions as $position) {
|
||||
try {
|
||||
|
@ -84,7 +84,7 @@
|
||||
$stmt = self::db()->prepare($query);
|
||||
$params = [ $userId, $name, $comment ];
|
||||
$stmt->execute($params);
|
||||
$trackId = self::db()->lastInsertId("${table}_id_seq");
|
||||
$trackId = (int) self::db()->lastInsertId("${table}_id_seq");
|
||||
} catch (PDOException $e) {
|
||||
// TODO: handle exception
|
||||
syslog(LOG_ERR, $e->getMessage());
|
||||
@ -158,7 +158,7 @@
|
||||
$ret = false;
|
||||
if (empty($name)) { $name = $this->name; }
|
||||
if (is_null($comment)) { $comment = $this->comment; }
|
||||
if ($comment == "") { $comment = NULL; }
|
||||
if ($comment === "") { $comment = NULL; }
|
||||
if ($this->isValid) {
|
||||
try {
|
||||
$query = "UPDATE " . self::db()->table('tracks') . " SET name = ?, comment = ? WHERE id = ?";
|
||||
@ -184,9 +184,7 @@
|
||||
*/
|
||||
public static function deleteAll($userId) {
|
||||
$ret = false;
|
||||
if (!empty($userId)) {
|
||||
// remove all positions
|
||||
if (uPosition::deleteAll($userId) === true) {
|
||||
if (!empty($userId) && uPosition::deleteAll($userId) === true) {
|
||||
// remove all tracks
|
||||
try {
|
||||
$query = "DELETE FROM " . self::db()->table('tracks') . " WHERE user_id = ?";
|
||||
@ -198,8 +196,6 @@
|
||||
syslog(LOG_ERR, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@
|
||||
$query = "INSERT INTO $table (login, password) VALUES (?, ?)";
|
||||
$stmt = self::db()->prepare($query);
|
||||
$stmt->execute([ $login, $hash ]);
|
||||
$userid = self::db()->lastInsertId("${table}_id_seq");
|
||||
$userid = (int) self::db()->lastInsertId("${table}_id_seq");
|
||||
} catch (PDOException $e) {
|
||||
// TODO: handle exception
|
||||
syslog(LOG_ERR, $e->getMessage());
|
||||
|
Loading…
x
Reference in New Issue
Block a user