last day (14 days later) » 

11:00 AM
0
Q: SQLSTATE[HY000] [2002] Connection refused with Laravel when attempting to write data to the database

Dave ChambersI have been using the Laravel package for the Wordpress JSON REST API and it works well. I want to store my blogposts in my database. I used phpMyAdmin to add a table named idybrand_laravel I created a file app/blogpost <?php namespace App; use Illuminate\Database\Eloquent\Model; class ...

 
in blogpost model you need to add fillable columns try this..
 
@Sona Cheers - I'll try
 
protected $fillable = [ 'fname', 'lname' ];like this.. ad your column names
and you are doing in local system keep password as empty in env file...
 
@Sona I left the password blank and added protected $fillable = array('id', 'wp_id', 'link', 'title', 'author_code', 'content', 'created_at', 'updated_at'); but got the same error sadly :-(
 
keep username as root'
 
11:00 AM
@Sona DB_USERNAME=root DB_PASSWORD= Same error
 
protected $table = 'tablename'; in model
keep that once
 
Above the fillable?
 
yup
 
Thanks for the help but protected $table = 'blogposts'; also didn't work
 
not working
your code
that the error is going regarding env and datbaase files
now code is clear
check thoase two files once
and let me know which version of laravel you are using
 
11:05 AM
.env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=idybrand_laravel
DB_USERNAME=root
DB_PASSWORD=
    'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],
 
this i sthe only code you have in .env file
 
version??
 
total thing:
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=idybrand_laravel
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls

PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
 
you are not sstteg th eapp key
generate app key
in env file
you are keeping correct database name there
 
11:08 AM
there is an app key but I just excluded it because I thought we were not supposed to share such things!! :-)
 
ok fine
 
I think Laravel is latest version
 
5.4 or 5.3
 
Sorry for the dumb question but how do I check?
 
@Dave
Could you check if MySQL is running?
 
11:21 AM
sure. How? Sorry, I'm an iOS Developer learning Laravel!!
from Terminal.......?
 
is phpmyadmin still working?
if it is still working then MySQL is still running
to check your laravel version try the following link: webqom.com/blog/how_to_check_your_laravel_version.html
 
When you changed your .env file with new username/pass have you done the same with MySQL database in phpmyadmin?
 
a cli option is here:
php artisan --version
 
Laravel Framework version 5.3.30
@Ku
@KuKeC, I set my .env file according to what I put in phpMyAdmin
 
Have you given priveleges for that database for created user?
Example of privileges for database of mine which is working is
 
11:27 AM
Yes
I gave myself all the priveledges AFAIK
 
but for that database
not for whole phpmyadmin
 
Wait a second I'll try and check
I can't see how to set the privileges for that table but I will Google and try to do that
 
database, not table
 
yep, DB
 
click on database
go on privileges
 
11:34 AM
I clicked the DB but there is no privileges
Anyway, I have to go to a meeting now but I'll try and set the database privileges after and comment if it helps
 
12:02 PM
I am logged into phpMyAdmin on the server that hosts my site. I see no 'Users' tab:
It says my user is User: idybrand@localhost
 
you need to change that
or add one more user with the same name
but with host %
or the ip you will be connecting from remotely
 
How?
I should a new phpMyAdmin user?
from Cpanel?
What do you mean:
database server isn't started, check if you can still use your phpmyadmin. If you can still use it then nothing is wrong with your database server.
I am developing the site locally using php artisan serve
how do I check if server is started?
 
nevermind the phpmyadmin part, I already see you are using it
so nothing wrong with server not started
use phpmyadmin to add a new user
 
but there is NO USERS TAB!!!
see my picture
 
you can use the same username and password as idybrand
there should be a privileges tab
 
12:11 PM
Please see the picture
NO privileges
NO users
I appreciate your help but it seems phpMyAdmin is faulty
 
no no
click on your database on the left
and see if you then get the tab
 
still no users or privs
I can upload a photo if you wish
NO SUCH SETTINGS :-(
Should I go back up to Cpanel?
 
hold on
where is the mysql server hosted?
locally on development machine?
 
no
on the server
is that wrong!!!???
 
no no
wait a sec
 
12:15 PM
ok
 
do you buy hosting or do you own your own server
 
I noticed you said cpanel, so I assume your using a hosted plan
 
from Siteground
 
okay no where getting somewhere
 
12:16 PM
you assume correctly
 
most of these give you privileges to only a certain part of the server
 
Sorry davejal, I am a beginner
 
that's why you don't have the tabs
no problem
 
just here to help
when you created the user they usually also send the configs you should use
 
12:17 PM
so I can't make my own tables?
 
by email or send you a link how to configure your connection
 
ok - I should contact Siteground then
 
yes you can create your own tables
 
They have Live CHat
 
but connection settings are wrong
 
12:18 PM
I will ask them later
I have to go now
But thanks very much for your help :-)
 
cheers
 
but I would recommend to learn on a local machine, makes it easier to start
good luck
 
so should I 'host' my own database locally?
to test such things?
 
I would recommend starting with a virtual machine
you could create a virtual machine using different hypervisors (vitrualbox for example)
 
12:25 PM
ok
 
then you could start learning the basics of laravel, so you don't run into problems not related to laravel
 
sure. ok. thanks for the advice :-)
 
at this moment I really think your problem has to do with connection settings, as hosting companies provide specific ways to connect
 
ok - I'll ask them
:-)
 
check in if you still have problems
 
12:27 PM
is that ok? I'll get in touch
 
yes no prob
 
Thanks man. Take it easy
 

last day (14 days later) »