I want to let users create a database. The query looks like this:
DB::statement( 'CREATE DATABASE mydbname' )
I need to use DB::statement
instead of DB::select
/ DB::select
/ DB::update
as the latter commands do not support the create
statement.
I want to protect myself from SQL injection and unfortunately, the following two methods do not work with DB::statement
:
DB::statement( 'CREATE DATABASE :DBNAME', [ 'DBNAME', 'mydbname' ] );
DB::statement( 'CREATE DATABASE ?', [ 'mydbname' ] );
So how could I protect the DB::statement
method from SQL injection? If that's not possible how could I trigger the create
query in a protected laravel way without using raw PHP-PDO?