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