I am the freshman in laravel development.
I use the mysql database, and want to insert the raw data in the database. I add the column with $table->binary()
. And how can I insert the data to the column.
Schema::table('users', function($table)
{
$table->binary('raw');
});
DB::raw() is used to make arbitrary SQL commands which aren't parsed any further by the query builder. They therefore can create a vector for attack via SQL injection. Since the query builder is using PDO in the background, we know there is a way to bind parameters to our query so it will sanitize the bound variables.
What are Raw Expressions? Raw Expressions allow you to tell the query builder that you want to use what you entered and not get processed or manipulate before running the query against the database. In Laravel 4.2 I used them for subselects. They come in 2 forms, on the DB facade or an Expression class.
After configuring the database, we can retrieve the records using the DB facade with select method. The syntax of select method is as shown in the following table. Run a select statement against the database.
You can use this way for raw insert ( I test this on laravel/Lumen 8 ) :
DB::insert('insert into users (email, votes) values (?, ?)', ['[email protected]', '0']);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With