php - Laravel: SQL LEFT JOIN with an INSERT (FOREIGN KEYS)
Get the solution ↓↓↓Solution:
You can fix that error by adding modes, only these modes will be enabled.
config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'xyz_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'modes' => [
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_AUTO_CREATE_USER',
'NO_ENGINE_SUBSTITUTION',
]
],
You can read more about modes here:
Answer
Solution:
In case anyone else stumbles across this and it can be useful to anyone... As @ross-wilson suggested, I was selecting multiplerep_id
per user in theSELECT
part of the SQL, which is why I was getting an error. I ended up just having to useGROUP BY
to make sure that only the lastrep_id
was being used, so each user only gets inserted into the table once.
DB::insert("
INSERT INTO user_registration_meta (user_id,rep_id)
SELECT users.id AS user_id,
COALESCE(rs.rep_id,elt(floor(rand() * $array_length + 1), $active_reps ),0) AS rep_id
FROM users
LEFT JOIN rep_sessions rs ON users.id=rs.user_id
GROUP BY users.id");
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the process class relies on proc_open, which is not available on your php installation.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.