{"id":10195,"date":"2023-02-14T08:53:59","date_gmt":"2023-02-14T08:53:59","guid":{"rendered":"https:\/\/www.bodhost.com\/kb\/?p=10195"},"modified":"2026-02-26T14:02:45","modified_gmt":"2026-02-26T14:02:45","slug":"php-script-to-test-mysql-database-connectivity","status":"publish","type":"post","link":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/","title":{"rendered":"PHP Script to Test MySQL Database Connectivity"},"content":{"rendered":"\n<p>A test for MySQL database connectivity is done using the PHP script mentioned below. It results in showing the tablet names that exist within the specified database.<\/p>\n\n\n\n<p><strong>Sample Script<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    &lt;!--?\n$connect=mysql_connect(\"dbserver\",\"dbuser\",\"dbpassword\") or die(\"Unable to Connect\");\nmysql_select_db(\"dbname\") or die(\"Could not open the db\");\n$showtablequery=\"SHOW TABLES FROM dbname\";\n$query_result=mysql_query($showtablequery);\nwhile($showtablerow = mysql_fetch_array($query_result))\n{\necho $showtablerow&#91;0].\" \";\n} \n?--&gt;<\/code><\/pre>\n\n\n\n<p><strong>Here is some of the clarification of the variables used in the script above:<\/strong><\/p>\n\n\n\n<p><strong>Step 1.<\/strong> dbserver: Linux hosting\u2019s (cPanel) value as localhost needs to be noted. The MySQL Server IP should be added for windows hosting.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"459\" src=\"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB.jpg\" alt=\"\" class=\"wp-image-10200\" srcset=\"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB.jpg 652w, https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB-300x211.jpg 300w, https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB-230x162.jpg 230w, https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB-350x246.jpg 350w, https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB-480x338.jpg 480w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><\/figure>\n\n\n\n<p><strong>Step 2.<\/strong> dbname: mention the entire database name along with the prefix such as <em>reseloaq_mysql<\/em>.<\/p>\n\n\n\n<p><strong>Step 3.<\/strong> dbuser: Specify the database user as well.<\/p>\n\n\n\n<p><strong>Step 4.<\/strong> dbpassword: Specify the database user\u2019s password.\u00a0<\/p>\n\n\n\n<p>I hope everything was clear and easy to understand. Please get in touch with the <strong><a href=\"https:\/\/www.bodhost.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">bodHOST<\/a><\/strong> support team as soon as possible with any questions.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Read Also: <a href=\"https:\/\/www.bodhost.com\/kb\/how-to-connect-plesk-with-external-database-servers\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Connect Plesk with External Database Servers<\/a><\/strong><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>A test for MySQL database connectivity is done using the PHP script mentioned below. It results in showing the tablet names that exist within the specified database. Sample Script Here is some of the clarification of the variables used in the script above: Step 1. dbserver: Linux hosting\u2019s (cPanel) value as localhost needs to be [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[836],"tags":[1382,1381],"class_list":["post-10195","post","type-post","status-publish","format-standard","hentry","category-database","tag-mysql-database-connectivity","tag-php-script-to-test-mysql-database-connectivity"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PHP Script to Test MySQL Database Connectivity<\/title>\n<meta name=\"description\" content=\"In this KB we have explained about PHP Script to Test MySQL Database Connectivity\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP Script to Test MySQL Database Connectivity\" \/>\n<meta property=\"og:description\" content=\"In this KB we have explained about PHP Script to Test MySQL Database Connectivity\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - bodHOST\" \/>\n<meta property=\"article:published_time\" content=\"2023-02-14T08:53:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T14:02:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"652\" \/>\n\t<meta property=\"og:image:height\" content=\"459\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Paul Lopez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Lopez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/\"},\"author\":{\"name\":\"Paul Lopez\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/566ccff9a2fae4af852be8097b179813\"},\"headline\":\"PHP Script to Test MySQL Database Connectivity\",\"datePublished\":\"2023-02-14T08:53:59+00:00\",\"dateModified\":\"2026-02-26T14:02:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/\"},\"wordCount\":139,\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/DB.jpg\",\"keywords\":[\"MySQL Database Connectivity\",\"PHP Script to Test MySQL Database Connectivity\"],\"articleSection\":[\"Database\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/\",\"name\":\"PHP Script to Test MySQL Database Connectivity\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/DB.jpg\",\"datePublished\":\"2023-02-14T08:53:59+00:00\",\"dateModified\":\"2026-02-26T14:02:45+00:00\",\"description\":\"In this KB we have explained about PHP Script to Test MySQL Database Connectivity\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/DB.jpg\",\"contentUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2023\\\/02\\\/DB.jpg\",\"width\":652,\"height\":459},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/php-script-to-test-mysql-database-connectivity\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Database\",\"item\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/category\\\/database\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP Script to Test MySQL Database Connectivity\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"alternateName\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"contentUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"width\":240,\"height\":240,\"caption\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/566ccff9a2fae4af852be8097b179813\",\"name\":\"Paul Lopez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"caption\":\"Paul Lopez\"},\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/author\\\/paullopez\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP Script to Test MySQL Database Connectivity","description":"In this KB we have explained about PHP Script to Test MySQL Database Connectivity","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/","og_locale":"en_US","og_type":"article","og_title":"PHP Script to Test MySQL Database Connectivity","og_description":"In this KB we have explained about PHP Script to Test MySQL Database Connectivity","og_url":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/","og_site_name":"Knowledge Base - bodHOST","article_published_time":"2023-02-14T08:53:59+00:00","article_modified_time":"2026-02-26T14:02:45+00:00","og_image":[{"width":652,"height":459,"url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB.jpg","type":"image\/jpeg"}],"author":"Paul Lopez","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Paul Lopez","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/#article","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/"},"author":{"name":"Paul Lopez","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/566ccff9a2fae4af852be8097b179813"},"headline":"PHP Script to Test MySQL Database Connectivity","datePublished":"2023-02-14T08:53:59+00:00","dateModified":"2026-02-26T14:02:45+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/"},"wordCount":139,"publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB.jpg","keywords":["MySQL Database Connectivity","PHP Script to Test MySQL Database Connectivity"],"articleSection":["Database"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/","url":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/","name":"PHP Script to Test MySQL Database Connectivity","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/#primaryimage"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/#primaryimage"},"thumbnailUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB.jpg","datePublished":"2023-02-14T08:53:59+00:00","dateModified":"2026-02-26T14:02:45+00:00","description":"In this KB we have explained about PHP Script to Test MySQL Database Connectivity","breadcrumb":{"@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/#primaryimage","url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB.jpg","contentUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2023\/02\/DB.jpg","width":652,"height":459},{"@type":"BreadcrumbList","@id":"https:\/\/www.bodhost.com\/kb\/php-script-to-test-mysql-database-connectivity\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Database","item":"https:\/\/www.bodhost.com\/kb\/category\/database\/"},{"@type":"ListItem","position":2,"name":"PHP Script to Test MySQL Database Connectivity"}]},{"@type":"WebSite","@id":"https:\/\/www.bodhost.com\/kb\/#website","url":"https:\/\/www.bodhost.com\/kb\/","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","description":"","publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"alternateName":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bodhost.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.bodhost.com\/kb\/#organization","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","url":"https:\/\/www.bodhost.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","contentUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","width":240,"height":240,"caption":"Web Hosting Knowledge Base | bodHOST Hosting FAQ"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/566ccff9a2fae4af852be8097b179813","name":"Paul Lopez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","caption":"Paul Lopez"},"url":"https:\/\/www.bodhost.com\/kb\/author\/paullopez\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/10195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/comments?post=10195"}],"version-history":[{"count":4,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/10195\/revisions"}],"predecessor-version":[{"id":10201,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/10195\/revisions\/10201"}],"wp:attachment":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/media?parent=10195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/categories?post=10195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/tags?post=10195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}