0

I created a database called learning-laravel and I created a table which is users I want to get data from that table I wrote this code block:

Route::get('/',function()
{   
    $users = DB::table('users')->get();
    return $users;
});

but I'm getting this type of error:

PDOException
SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:3306' (2)



  */
    public function createConnection($dsn, array $config, array $options)
    {
        $username = array_get($config, 'username');

        $password = array_get($config, 'password');

        return new PDO($dsn, $username, $password, $options);
    }
10
  • is this the correct host? localhost:8889 Commented Dec 16, 2013 at 17:27
  • yeah mysql settings is keeping in localhost:8889 Commented Dec 16, 2013 at 17:28
  • can you show the code where you specify the host and port number? Commented Dec 16, 2013 at 17:30
  • my database.php file 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost:3306', 'database' => 'database', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ), Commented Dec 16, 2013 at 17:31
  • I checked my MAMP server APACHE post:8888 MySQL post:3306 I think there should be no error Commented Dec 16, 2013 at 17:33

3 Answers 3

1

Try instead of including the port in the host, add a "port" key and the port in a seperate key.

    'host'     => 'localhost',
    'port'     => '8889'

Looks like it may be trying to use that entire string as the host name.

Sign up to request clarification or add additional context in comments.

Comments

0

As you said in your comment above, you have your MAMP settings pointing MySQL requests to port 3306. Here is the correct setting in that case:

'host' => 'localhost',
'port' => '3306'

Also, the "is it plugged in" suggestion would be to make sure your DB is actually running.

Comments

0

The solution is:

'host'      => 'localhost:3306',

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.