samedi 25 mars 2017

How to get laravel DB connection to php connection?

I need to receive laravel DB connection to variable to make concrete pure SQL php demands on a database. Desired code:

<?php 
// this is not working
$conn = DB::connection();

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

Desired result: "Connected successully"

I need it because I have very complex SQL demands that I need to put in one query, not using laravel query syntax (I believe it is better approach, but I have complex queries and need to use pure query text to execute, not laravel "->" syntax)

I need to get laravel DB connection to not always often establish second php connection like with PDO or writing down DB credentials. If PDO connection to DBS from laravel exists, it could be useful to obtain to php for me too.

DB::connection()->name

returns a name of DB, but thats no connection :/

I was looking for it but nowhere found solution for that, could someone help me find correct answer please? (maybe it is not important, but I use mysql)



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2nAmOKd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire