{"id":24,"date":"2008-03-10T22:21:42","date_gmt":"2008-03-11T06:21:42","guid":{"rendered":"http:\/\/staging.www.zenutech.com\/kb\/databases\/connecting-to-mysql-with-php\/"},"modified":"2024-04-10T10:04:19","modified_gmt":"2024-04-10T15:04:19","slug":"connecting-to-mysql-with-php","status":"publish","type":"post","link":"https:\/\/www.zenutech.com\/kb\/article\/connecting-to-mysql-with-php\/","title":{"rendered":"Connecting to MySQL with PHP"},"content":{"rendered":"<p>You can connect to MySQL with hostname &#8220;localhost&#8221;.<\/p>\n<p>The following example connects to database &#8220;cpname_database&#8221; with username &#8220;cpname_user&#8221; and password &#8220;your_password&#8221;.  You will need to substitute these values for your actual database, username, and password you setup in the hosting control panel (<a href=\"\/kb\/article\/how-do-i-prepare-a-database-for-my-website\/\" target=\"_blank\">instructions<\/a>)<\/p>\n<pre>\r\n\/\/\/\/\/\/ establish connection to MySQL as the \"cpname_user\" user and make \"cpname_database\" the current database \/\/\/\/\/\/\r\n$link = mysqli_connect('localhost', 'cpname_user', 'your_password', 'cpname_database');\r\n\r\nif (!$link) {\r\n\u00a0  die('Not connected : ' . mysqli_connect_error());\r\n}<\/pre>\n<p>Please consult the <a href=\"https:\/\/www.php.net\/manual\/en\/mysqli.construct.php\">PHP documentation<\/a> for more details.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An example of connecting to MySQL with PHP.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10],"tags":[292,48,52,294],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-databases","category-web-development","tag-databases","tag-mysql","tag-php","tag-web-development"],"_links":{"self":[{"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":4,"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":707,"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/posts\/24\/revisions\/707"}],"wp:attachment":[{"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zenutech.com\/kb\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}