Support the ongoing development of Laravel.io →
Configuration Database

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!

Last updated 2 years ago.
0

Have you turned on debugging in your app config file?

Last updated 2 years ago.
0

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'
Last updated 2 years ago.
0

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...

Last updated 2 years ago.
0

Thanks it did. This also helped: http://laravel.com/docs/database

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.