Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Illuminate Database Query Builder & Eloquent in other framework with PHP 5.3.x
    text
    copied!<p>I did a couple of projects with Laravel in the past but now I need something very light for a project and went to use Slim, it works great for what I need and I want the great Eloquent ORM and Query Builder of Laravel, can't go without it now :) Now I manage to get it all working with composer, using the information that Taylor displayed on his GitHub, copied his piece of code</p> <pre><code>use Illuminate\Database\Capsule\Manager as Capsule; $capsule = new Capsule; $capsule-&gt;addConnection([ 'driver' =&gt; 'mysql', 'host' =&gt; 'localhost', 'database' =&gt; '', 'username' =&gt; '', 'password' =&gt; '', 'charset' =&gt; 'utf8', 'collation' =&gt; 'utf8_unicode_ci', 'prefix' =&gt; '', ]); // Set the event dispatcher used by Eloquent models... (optional) use Illuminate\Events\Dispatcher; use Illuminate\Container\Container; $capsule-&gt;setEventDispatcher(new Dispatcher(new Container)); // Set the cache manager instance used by connections... (optional) $capsule-&gt;setCacheManager(...); // Make this Capsule instance available globally via static methods... (optional) $capsule-&gt;setAsGlobal(); // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher()) $capsule-&gt;bootEloquent(); </code></pre> <p>That works perfectly good on my local dev (PHP 5.4.x) but when I put it on my server <b>PHP 5.3.x</b>, it just doesn't work anymore :( Now I see 1 problem being that we can't use anonymous array like this <code>[]</code> but instead should be written the old way of <code>array()</code>, that is inside the <code>addConnection(array($settings))</code> great, now a little further...but then after it seems to crash inside <code>$capsule-&gt;setEventDispatcher()</code> and I don't have logs on my server (I only found through var_dump() here and there), it's just a NAS and I don't want to even think of spending a few hours just to find out how to enable it. But what's funny is that I had a Laravel 4 project working with it... so why just building a part of it <code>Illuminate\Database</code> doesn't work then? I also found another piece of code to make Eloquent ORM work in PHP 5.3.x</p> <pre><code>$settings = array( 'driver' =&gt; '', 'host' =&gt; '127.0.0.1', 'database' =&gt; '', 'username' =&gt; '', 'password' =&gt; '', 'charset' =&gt; "utf8", 'collation' =&gt; 'utf8_general_ci', 'prefix' =&gt; '' ); // Bootstrap Eloquent ORM $connFactory = new \Illuminate\Database\Connectors\ConnectionFactory(new Illuminate\Container\Container); $conn = $connFactory-&gt;make($settings); $resolver = new \Illuminate\Database\ConnectionResolver(); $resolver-&gt;addConnection('default', $conn); $resolver-&gt;setDefaultConnection('default'); \Illuminate\Database\Eloquent\Model::setConnectionResolver($resolver); </code></pre> <p>but if I use this piece of code, which is good with Models by the way. I need to use <code>$conn-&gt;table('...')...</code> instead of the Facade simple way of <code>DB::table(....)</code> which is what I want, why is it important you would say? Well what if I want to convert to Laravel in the future... I would have to change all of the <code>$conn-&gt;</code> to <code>DB::</code> so I would rather do it right the first time. If someone knows how to create Facade on the 2nd piece of code, I would be happy too... Thanks for any help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload