Skip to content

Writing twice to sqlite database and get error SQLSTATE[HY000]: General error: 5 database is locked #40

Description

@ffuentese

I wrote the following function to get input from the user

app()->post('/createThread', function () {
        
  $user = auth()->user()->get();
  if (!$user) {
      return response()->render('login',[
      'status' => 'error',
      'message' => 'Debe iniciar sesión',
      'data' => auth()->errors(),
    ]);
  }
 
$userData = request()->get(['title', 'message', 'topic_id']);
$db = db();
    $db->insert('threads')->params([
        'title' => $userData['title'],
        'user_id' => auth()->id(),
        'topic_id' => $userData['topic_id']
   ])->execute();
 
  $thread_id = $db->lastInsertId();
 
$db->insert('comments')->params([
        'message'=>$userData['message'],
        'user_id' => auth()->id(),
        'thread_id'=>$thread_id
 ])->execute();
 
  return response()->redirect('/thread/{$thread_id}');
 
});

However, I'm getting the aforementioned error 5 and I tried with the transaction function callback but I get another error "no active transaction". The documentation is not super exhaustive and no resource is helpful. Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions