Support the ongoing development of →
Database Eloquent Architecture
Last updated 2 years ago.

If anyone want to know how to add a function to sqlite database without having to hack to source code. If you are using PDO then its real easy and even easier when the functions you want to add are part of the programming language used with PDO .

So add this to your project I used the AppServiceProvider register method.

		$pdo = DB::connection('sqlite')->getPdo();
		$pdo->sqliteCreateFunction('cos', 'cos', 1);
		$pdo->sqliteCreateFunction('acos', 'acos', 1);
		$pdo->sqliteCreateFunction('sin', 'sin', 1);
		$pdo->sqliteCreateFunction('radians', 'deg2rad', 1);

Fixed it I was missing a BD::raw within the having as i was using a bind param

 DB::raw("*,  ( 6371 * acos( cos( radians(?) ) * cos( radians( `latitude` ) ) * cos( radians( `longitude` ) - radians(?) ) + sin( radians(?) ) * sin( radians( `latitude` ) ) )) AS distance"))
            ->having("distance", "<", DB::raw('?'))
            ->setBindings([$latitude, $longitude, $latitude, $radius])


Sign in to participate in this thread!


Your banner here too?

apps4u apps4u Joined 7 Apr 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.