# DB Connection with XAMPP

**URL:** <https://discourse.cakephp.org/t/db-connection-with-xampp/8968>\
**Category:** Need Help\
**Tags:** help\
**Created:** [February 6, 2021, 8:44pm UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968 "2021-02-06T20:44:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![coderHi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/coderhi/32/2115_2.png) [@coderHi](https://discourse.cakephp.org/u/coderHi)\
**Post date:** [February 6, 2021, 8:44pm UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968/1 "2021-02-06T20:44:29Z")

</div>

Hi !

I’m really glad I have chosen to learn cakePHP to strength my programming skills! But I am having issues connecting to my database.  
I am following the creating a first app guide and I’m having problems getting cake to connect to my phpmyadmin database.

- I have the cake server running on default ports 8765. And I have my XAMPP server running on 8080.
- I have created the db tables in phpmyadmin on xampp server.
- I have set up the app\_local.php db connection code with the correct credentials and pointing to localhost:8080 which is where phpmyadmin in xampp is.

Is this the right way to set everything on? Feels a bit clunky running xampp as well as cake server…

Much help is appreciated, I cannot get the green DB connection icon!

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Jawfin](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@Jawfin](https://discourse.cakephp.org/u/Jawfin)\
**Post date:** [February 7, 2021, 1:54am UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968/2 "2021-02-07T01:54:37Z")

</div>

Howdy!

There’s a few things going on, we’re looking at full stack, so your XAMPP is making your PC behave like a webserver, and handling the SQL & PHP etc. The CakePHP server app is really just triggering the php translator to pick up the code you have there in your app (so one cake server app for each cake app - if that makes sense).

What you may be missing is that you need to set your SQL values in your `cfg/app_local.php` file. Look for and correct these values to how you have your SQL server: -

```auto
    'Datasources' => [
        'default' => [
            'host' => 'localhost',
            'username' => 'root',
            'password' => 'secret',
            'database' => 'cake_db',

```

as the wizard/bake does not do that for you (at least, it didn’t when I last played with it).

Failing that you may need to copy/paste your debug info (ensuring no private data is shared) to a post here.

Hope that helps.

Cheers  
Jonathan

Edit: I just noticed this comment in that same file: -

```auto
            /*
             * CakePHP will use the default DB port based on the driver selected
             * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
             * the following line and set the port accordingly
             */
            //'port' => 'non_standard_port_number',

```

(ironic that I copy/pasted _around_ it!) so you may need to set the port too.

---

<div class="post-metadata">

**Author:** ![coderHi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/coderhi/32/2115_2.png) [@coderHi](https://discourse.cakephp.org/u/coderHi)\
**Post date:** [February 7, 2021, 8:25am UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968/3 "2021-02-07T08:25:31Z")

</div>

This is the only error I’m getting on the original welcome page.

> CakePHP is NOT able to connect to the database. Connection to Mysql could not be established: SQLSTATE[HY000] [2002] No such file or directory

This is my config settings:

 ![Screenshot 2021-02-07 at 09.24.34](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/d/d1167c5a54ba4835a7d6d0f72bc81421a1536b14.png)

---

<div class="post-metadata">

**Author:** ![coderHi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/coderhi/32/2115_2.png) [@coderHi](https://discourse.cakephp.org/u/coderHi)\
**Post date:** [February 7, 2021, 8:29am UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968/4 "2021-02-07T08:29:09Z")

</div>

![Screenshot 2021-02-07 at 09.26.30](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/e/e52c089d35222699a00eca85cb4b30c72cd5b46d.png)

When I start the server I get this PHP warning message. And the in path is blank. Could that be causing any issues?

---

<div class="post-metadata">

**Author:** ![Jawfin](https://avatars.discourse-cdn.com/v4/letter/j/dbc845/32.png) [@Jawfin](https://discourse.cakephp.org/u/Jawfin)\
**Post date:** [February 7, 2021, 2:56pm UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968/5 "2021-02-07T14:56:45Z")

</div>

Does it accept a blank password? (or you just removed it for your post.)

I don’t know if international settings would cause a problem though.

I can only suggest building a new test app, showing the commands use in doing so, and the structure of your SQL creation script.

For comparison, I did this, running XAMPP (all default I think!).

![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/a/ae6ee21ea7b5d3784c93fe59ebffd6866493d04e.png)

Then made a new app, cake\_test: -  
`composer self-update `  
`composer create-project --prefer-dist cakephp/app:4.* cake_test`  
then run it  
`cd cake_test\bin`  
`cake server`  
(I run the server from within the \bin\ folder to resolve any relative paths a may have external to my CakePHP app.)

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/0/08178dedc8167fc396a83b20b846c1199093bca1.png)

And go to my new app, which is broken from the SQL

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/4/4ce0ba78e165850684e5e0b3d97574100690bc1e.png)

I then copy adminer.php into webroot (I love adminer!!)  
MySQL, English [https://github.com/vrana/adminer/releases/download/v4.7.8/adminer-4.7.8-mysql-en.php](https://github.com/vrana/adminer/releases/download/v4.7.8/adminer-4.7.8-mysql-en.php)  
I know phpmyadmin ships with XAMPP, but I still prefer adminer (just don’t publish it in your release!)

Using my credentials root/secret I login

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/9/90c75b51e8f29bbddd3cde069732ed6533d04265.png)

(I think I set that password ages ago, it may be blank password by default - but if you don’t know you may be up for reinstalling XAMPP for a clean MySQL)

I create my database, test

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/4/491195c212f3cbef776a38df8bdc6abdcbecdd42.png)

Update `config\app_local.php`: -

```auto
            'username' => 'root',
            'password' => 'secret',
            'database' => 'test',

```

and

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/d/d3e1e851d241c8497c1263f366e8226705cf55cd.png)

Done.

Note this is _all_ default values. I get default stuff to work first before I even consider tailoring it to my needs, and even then it’s one change at a time!  
After any change to your models or database clear the cache with `bin\cake cache clear_all`

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [February 7, 2021, 3:22pm UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968/6 "2021-02-07T15:22:31Z")

</div>

8080 is almost certainly the port where Apache is running, not MySQL. See @Jawfin’s XAMPP control panel screen shot, in his case (which is the standard), MySQL is running on 3306. Check your control panel to see where your MySQL is.

---

<div class="post-metadata">

**Author:** ![jbailer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jbailer/32/2393_2.png) [@jbailer](https://discourse.cakephp.org/u/jbailer)\
**Post date:** [December 6, 2021, 1:20pm UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968/7 "2021-12-06T13:20:54Z")

</div>

I’m running all conventional ports (3306 for MySQL) and while I can get ‘cake server’ to give the splash page, it refuses to connect to my database. I can connect to the database with both phpMyAdmin and MySQLWorkbench without issue. I can add tables, users, etc. with zero issue. But, when I add the credentials in `app_local.php` as shown in the CakePHP instructions, it just refuses to connect. I’m at a loss, after a day of trying I’m getting nowhere.

```auto
    'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'port' => 3306,
            'persistent' => false,
            'host' => 'localhost',
            'username' => 'root',
            'password' => 'password',
            'database' => 'cake_php',
            'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'cacheMetadata' => true,
        ],

```

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [December 6, 2021, 2:01pm UTC](https://discourse.cakephp.org/t/db-connection-with-xampp/8968/8 "2021-12-06T14:01:17Z")

</div>

Is phpMyAdmin running on the same server as your CakePHP application? What does “refuses to connect” mean, what error do you get?
