{"id":2996,"date":"2025-02-04T09:50:18","date_gmt":"2025-02-04T09:50:18","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=2996"},"modified":"2025-02-04T12:39:47","modified_gmt":"2025-02-04T12:39:47","slug":"test-database-connection-is-ok-or-not","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/test-database-connection-is-ok-or-not\/","title":{"rendered":"Test Database Connection is ok or not"},"content":{"rendered":"\n<p>Laravel provides an interactive shell called <strong>Tinker<\/strong>, which allows you to test database connections easily. Run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php artisan tinker<\/code><\/pre>\n\n\n\n<p>Then, in the interactive shell, try the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DB::connection('NameDB')->getPdo();\necho \"Connected successfully to Name DB\";\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"488\" src=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/02\/image-1-1024x488.png\" alt=\"\" class=\"wp-image-2997\" srcset=\"https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/02\/image-1-1024x488.png 1024w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/02\/image-1-300x143.png 300w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/02\/image-1-768x366.png 768w, https:\/\/www.devopssupport.in\/blog\/wp-content\/uploads\/2025\/02\/image-1.png 1252w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If your connection is <strong>successful<\/strong>, it will return a message <strong>without errors<\/strong>.<br>If there is an issue, you will see a <strong>PDOException error<\/strong>, which could indicate:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Incorrect credentials in <code>.env<\/code><\/li>\n\n\n\n<li>Database is not running<\/li>\n\n\n\n<li>Incorrect database name or host<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Laravel provides an interactive shell called Tinker, which allows you to test database connections easily. Run: Then, in the interactive shell, try the following: If your connection&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[686,2433,2427,2429,2435,42,191,2006,824,2431,2432,2428,826,2434,100,2430,35,676,675],"class_list":["post-2996","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-database-connection","tag-database-debugging","tag-flarum","tag-flarum-integration","tag-flarum-setup","tag-laravel","tag-laravel-config","tag-laravel-database","tag-laravel-debugging","tag-laravel-env-2","tag-laravel-routes","tag-laravel-tinker","tag-laravel-troubleshooting","tag-laravel-tutorial","tag-mysql","tag-mysql-connection","tag-php","tag-php-artisan","tag-web-development"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/2996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=2996"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/2996\/revisions"}],"predecessor-version":[{"id":2998,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/2996\/revisions\/2998"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=2996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=2996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=2996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}