Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert raw data in mysql database in laravel

Tags:

php

mysql

laravel

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');
});
like image 776
firelyu Avatar asked Apr 30 '14 03:04

firelyu


People also ask

How write raw SQL query in Laravel?

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 is raw expression in Laravel?

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.

How can we get data from database in controller in Laravel?

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.


1 Answers

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']);
like image 88
Mohammad Ilbeygi Avatar answered Oct 06 '22 04:10

Mohammad Ilbeygi