I'm really excited about using Laravel, but there's one small problem - I can't connect to my database. I've been trying to get this work for hours now and I'm about ready to pull my hair out.
My apache and mysql services are running.
I was able to make the database 'learninglaravel' using phpMyAdmin. I created a table. Created a row. Verified it's in there. So far so good. I've verified thru command prompt that the database/table are there and they are.
I have a route in Laravel ready to display the info:
Route::get('/', function()
{
$posts = DB::query("SELECT * FROM posts");
print_r($posts);
});
I went into my database.php file and set the settings:
'mysql' => array(
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'learninglaravel',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
I also tried 'localhost' instead of '127.0.0.1', no difference. I tried adding the port using: 'port' => '3306'. no difference.
This is the route to my laravel project: F:\Apps\xampp\htdocs\laravel
And this is the route to my mysql: F:\Apps\xampp\mysql\bin
I even ran the command: php artisan migrate:install --env-local
Any help would be greatly appreciated please!
Have you turned on debugging in your app config file?
Yes sir:
ErrorException
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Database\MySqlConnection' does not have a method 'query'
Well, after a bit more digging around, it seems that DB::query does not really work so well in Laravel 4 (perhaps deprecated?)
But by using: DB::select("SELECT * from..... )
That does seem to work. So it seems that this is not so much a connection issue, but rather a using the proper command issue.
Hopefully this helps anyone trying to learn Laravel 4 using, apparently, a Laravel 3 tutorial...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community