{"id":3823,"date":"2013-06-06T11:16:39","date_gmt":"2013-06-06T11:16:39","guid":{"rendered":"https:\/\/bodhost.com\/kb\/?p=3823"},"modified":"2026-02-26T14:04:32","modified_gmt":"2026-02-26T14:04:32","slug":"cannot-connect-mysql-with-php-scripts","status":"publish","type":"post","link":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/","title":{"rendered":"Cannot Connect MySQL with PHP Scripts"},"content":{"rendered":"\r\n<p class=\"has-text-align-left\">If you cannot seem to connect to MySQL with a PHP script then it might happen due to the PHP scripts under a domain are not able to connect to the MySQL server. You might have mentioned the connection strings correctly but still not able to connect MySQL through scripts. To sort this error you can do the following steps:<\/p>\r\n\r\n\r\n\r\n<p><span style=\"color: purple; font-size: x-large;\">Locate the server&#8217;s php.ini.<\/span><\/p>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>[root@server ~]# php -i | grep php.ini<br \/>Configuration File (php.ini) Path =&gt; \/usr\/local\/lib<br \/>Loaded Configuration File =&gt; \/usr\/local\/lib\/php.ini<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p>Here we are considering the server is a su-exe server. Copy php.ini file to the document of the domain.<\/p>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>[root@server ~]# cp \/usr\/local\/lib\/php.ini \/home\/test\/public_html<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p>Once you have done this go to the document root of the domain and edit the php.ini file as follows:<\/p>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>[root@server ~]# cd \/home\/test\/public_html<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p>Open the php.ini file and locate the following line:<\/p>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>[root@server public_html]# vi php.ini<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p><span style=\"color: purple; font-size: x-large;\">Locate for the line:<\/span><\/p>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>[SQL]<br \/>sql.safe_mode = On<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p><span style=\"color: purple; font-size: x-large;\">Now change this flag setting to Off<\/span><\/p>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>[SQL]<br \/>sql.safe_mode = Off<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p><span style=\"color: purple; font-size: x-large;\">Save the settings and restart the Apache service on the server.<\/span><\/p>\r\n\r\n\r\n\r\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\r\n<p>[root@server ~]# \/etc\/init.d\/httpd restart<\/p>\r\n<\/blockquote>\r\n\r\n\r\n\r\n<p>Through these steps you will be able to connect MySQL with PHP scripts.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>If you cannot seem to connect to MySQL with a PHP script then it might happen due to the PHP scripts under a domain are not able to connect to&hellip;<\/p>\n<p><a href=\"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/\" class=\"more-link\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[206,489],"class_list":["post-3823","post","type-post","status-publish","format-standard","hentry","category-sql","tag-mysql","tag-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Cannot Connect MySQL with PHP Scripts<\/title>\n<meta name=\"description\" content=\"Resolve the issue of connecting MySQL with PHP scripts using this helpful guide.\" \/>\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\/cannot-connect-mysql-with-php-scripts\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Cannot Connect MySQL with PHP Scripts\" \/>\n<meta property=\"og:description\" content=\"Resolve the issue of connecting MySQL with PHP scripts using this helpful guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - bodHOST\" \/>\n<meta property=\"article:published_time\" content=\"2013-06-06T11:16:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T14:04:32+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\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\\\/cannot-connect-mysql-with-php-scripts\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/cannot-connect-mysql-with-php-scripts\\\/\"},\"author\":{\"name\":\"admin\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/c48414ad1536cea20e85282b0737a9f9\"},\"headline\":\"Cannot Connect MySQL with PHP Scripts\",\"datePublished\":\"2013-06-06T11:16:39+00:00\",\"dateModified\":\"2026-02-26T14:04:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/cannot-connect-mysql-with-php-scripts\\\/\"},\"wordCount\":224,\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"keywords\":[\"MySQL\",\"php\"],\"articleSection\":[\"SQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/cannot-connect-mysql-with-php-scripts\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/cannot-connect-mysql-with-php-scripts\\\/\",\"name\":\"Cannot Connect MySQL with PHP Scripts\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\"},\"datePublished\":\"2013-06-06T11:16:39+00:00\",\"dateModified\":\"2026-02-26T14:04:32+00:00\",\"description\":\"Resolve the issue of connecting MySQL with PHP scripts using this helpful guide.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/cannot-connect-mysql-with-php-scripts\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/cannot-connect-mysql-with-php-scripts\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/cannot-connect-mysql-with-php-scripts\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"SQL\",\"item\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/category\\\/sql\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Cannot Connect MySQL with PHP Scripts\"}]},{\"@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\\\/c48414ad1536cea20e85282b0737a9f9\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g\",\"caption\":\"admin\"},\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/author\\\/admin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Cannot Connect MySQL with PHP Scripts","description":"Resolve the issue of connecting MySQL with PHP scripts using this helpful guide.","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\/cannot-connect-mysql-with-php-scripts\/","og_locale":"en_US","og_type":"article","og_title":"Cannot Connect MySQL with PHP Scripts","og_description":"Resolve the issue of connecting MySQL with PHP scripts using this helpful guide.","og_url":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/","og_site_name":"Knowledge Base - bodHOST","article_published_time":"2013-06-06T11:16:39+00:00","article_modified_time":"2026-02-26T14:04:32+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/#article","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/"},"author":{"name":"admin","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/c48414ad1536cea20e85282b0737a9f9"},"headline":"Cannot Connect MySQL with PHP Scripts","datePublished":"2013-06-06T11:16:39+00:00","dateModified":"2026-02-26T14:04:32+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/"},"wordCount":224,"publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"keywords":["MySQL","php"],"articleSection":["SQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/","url":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/","name":"Cannot Connect MySQL with PHP Scripts","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/#website"},"datePublished":"2013-06-06T11:16:39+00:00","dateModified":"2026-02-26T14:04:32+00:00","description":"Resolve the issue of connecting MySQL with PHP scripts using this helpful guide.","breadcrumb":{"@id":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.bodhost.com\/kb\/cannot-connect-mysql-with-php-scripts\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"SQL","item":"https:\/\/www.bodhost.com\/kb\/category\/sql\/"},{"@type":"ListItem","position":2,"name":"Cannot Connect MySQL with PHP Scripts"}]},{"@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\/c48414ad1536cea20e85282b0737a9f9","name":"admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/51e53199212db3f59606920448d45a6ead224f904558e3ab9251d071a609b202?s=96&d=mm&r=g","caption":"admin"},"url":"https:\/\/www.bodhost.com\/kb\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/3823","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/comments?post=3823"}],"version-history":[{"count":15,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/3823\/revisions"}],"predecessor-version":[{"id":12247,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/3823\/revisions\/12247"}],"wp:attachment":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/media?parent=3823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/categories?post=3823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/tags?post=3823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}