5

I am trying to write a changelog using Laravel and have been asked to pull data from a MySQL database into an array; check in the array if an account ID exists based on values read in from JSON files.

If not present, I need to create it and add the data to the array.

The code I have at the moment adds entries to the database, but it does not do any sort of checking, my code is as follows:

if (isset($cfi->awsAccountId)) {
    $aid = new Account;
    $aid->aws_account_id = $cfi->awsAccountId;              
    $aid->save();
}
4

1 Answer 1

24

if anyone is still interested, it can be done as follows:

Demo controller code:

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;

class Testing extends Controller
{
   public function get()
   {
        $query = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME =  ?";
        $db = DB::select($query, [$your_database_name]);
        if (empty($db)) {
            echo 'No db exist of that name!';
        } else {
            echo 'db already exists!';
        }
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.