{"id":11032,"date":"2020-08-04T04:30:26","date_gmt":"2020-08-04T04:30:26","guid":{"rendered":"https:\/\/www.anychart.com\/blog\/?p=11032"},"modified":"2022-08-13T11:01:24","modified_gmt":"2022-08-13T11:01:24","slug":"mysql-database-php-js-chart","status":"publish","type":"post","link":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/","title":{"rendered":"Connecting MySQL Database to JS Chart Using PHP"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone size-full wp-image-11036\" src=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png\" alt=\"Connecting MySQL Database to JS Chart Using PHP\" width=\"100%\" srcset=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png 1400w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial-300x164.png 300w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial-768x421.png 768w, https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial-1024x561.png 1024w\" sizes=\"(max-width: 1400px) 100vw, 1400px\" \/>When using a <a href=\"https:\/\/www.anychart.com\/blog\/2017\/03\/05\/how-to-choose-the-right-javascript-charting-component-10-factors-you-have-to-consider\/\">charting library<\/a> like <a href=\"https:\/\/www.anychart.com\">AnyChart<\/a>, which makes visualizing data so quick and easy, often the most challenging step for beginners is loading data. I think this is largely a result of the fact that while the ways we output the data are quite similar, the input data is commonly very different. The data may differ in many ways including the number of features in the dataset, what type these features may be, the format of the data, and <strong>how the data is stored<\/strong>. It is this final issue which we will be addressing today.<\/p>\n<p>There is a lot of coverage in the <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Overview\" target=\"_blank\" rel=\"nofollow\">documentation<\/a> of using a data object declared within the code as well as importing your data from a file using AnyChart\u2019s data loader. But what about importing the data from an <a href=\"https:\/\/en.wikipedia.org\/wiki\/SQL\" target=\"_blank\" rel=\"nofollow\">SQL<\/a> database? This is an easily done but often misunderstood approach to handling and loading data for data visualizations.<\/p>\n<p>Unfortunately, it is not possible to use <a href=\"https:\/\/en.wikipedia.org\/wiki\/JavaScript\" target=\"_blank\" rel=\"nofollow\">JavaScript<\/a> to query a database because JavaScript is a client side solution and <strong>querying a database requires a server side approach<\/strong> due to security concerns \u2014 <strong>you just can\u2019t store database login and password in your JavaScript code<\/strong>. There are many workarounds for this problem including approaches involving PHP, Ajax, Node.js, and many more. Today we will focus on using <a href=\"https:\/\/www.php.net\" target=\"_blank\" rel=\"nofollow\">PHP<\/a> to handle this task for us when our data is stored in <a href=\"https:\/\/www.mysql.com\/\" target=\"_blank\" rel=\"nofollow\">MySQL<\/a>.<\/p>\n<p>In this tutorial, we will be covering <strong>how to query a MySQL database using PHP<\/strong>. We will describe the steps involved and reveal that it is in fact not challenging at all, just different!<\/p>\n<p><!--more Read the tutorial \u00bb--><\/p>\n<h2>How to Access MySQL Database Using PHP<\/h2>\n<p>Our process can be broken down into two clearly defined steps. First, we will use PHP to access our MySQL database before querying the table and appending the result into a <a href=\"https:\/\/en.wikipedia.org\/wiki\/JSON\" target=\"_blank\" rel=\"nofollow\">JSON<\/a> object. The second step simply draws the chart in the same way you\u2019ve been used to.<\/p>\n<h3>1. Create a PHP script<\/h3>\n<p>The first step is to create a PHP script. This can be done by using the following opening and closing tags. All code written within these tags are read by the server as PHP.<\/p>\n<pre><code class=\"html\">&lt;?php\r\n  \/\/ code goes here.\r\n?&gt;<\/code><\/pre>\n<h3>2. Declare MySQL database variables<\/h3>\n<p>Next, we declare our MySQL database variables required to access our database. We need the username, password, host, and database name. In the code below we have added dummy information for the purpose of showing you how this is done. Please replace these strings with the necessary information for your own database.<\/p>\n<p>Note that if you have set up a local database, the host name is \u201clocalhost\u201d and often the default username is \u201croot\u201d.<\/p>\n<pre><code class=\"php\">$username = \"anychart_user\"; \/\/ use your username  \r\n$password = \"password\";      \/\/ use your password\r\n$host = \"localhost\";         \/\/ use your host name or address \r\n$database=\"local_db\";        \/\/ use your database name<\/code><\/pre>\n<h3>3. Connect to database<\/h3>\n<p>In the third step, we will connect to our database using the previously defined variables. We do so with the following code. The first line creates the connection to the server while the second line connects us to the correct database.<\/p>\n<pre><code class=\"php\">\/\/ connect to database\r\n$server = mysql_connect($host, $username, $password);\r\n$connection = mysql_select_db($database, $server);<\/code><\/pre>\n<h3>4. Perform query<\/h3>\n<p>Once our connection is made, we can perform a query. For those of you new to using SQL, a query is effectively an enquiry to a database that returns the requested data. Below, we do a simple query that fetches all the fields and all the values from an example table. You should replace this with the appropriate query for your needs. The first 3 lines create the query string while the final line performs the query.<\/p>\n<pre><code class=\"php\">\/\/ perform query\r\n\/\/ you may need to tune the query if your database is different\r\n$myquery = \"\r\n  SELECT * FROM  `data`\r\n  \";\r\n$query = mysql_query($myquery);<\/code><\/pre>\n<p>We then add the following code to let us know if the query returns no data:<\/p>\n<pre><code class=\"php\">if ( ! $query ) {\r\n  echo mysql_error();\r\n  die;\r\n}<\/code><\/pre>\n<h3>5. Create data from the query<\/h3>\n<p>In the fifth step, we declare \u2018data\u2019 variable as an empty array before populating this array with the results of our returned query. We do this by iterating over the returned query data with a for loop.<\/p>\n<pre><code class=\"php\">\/\/ create data object\r\n$data = array();\r\n\r\nfor ($x = 0; $x &lt; mysql_num_rows($query); $x++) {\r\n  $data[] = mysql_fetch_assoc($query);\r\n}<\/code><\/pre>\n<h3>6. Encode data to JSON format<\/h3>\n<p>Now that we have our data in an array we need to transform it into a format that can be used with AnyChart. AnyChart works with a <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Supported_Data_Formats\" target=\"_blank\" rel=\"nofollow\">variety of formats<\/a>, including CSV, JSON, XML, and even Google Spreadsheets.\u00a0This time,\u00a0we will encode our data as a JSON. This is easily done with the following code:<\/p>\n<pre><code class=\"php\">\/\/ encode data to json format\r\necho json_encode($data);<\/code><\/pre>\n<h3>7. Close connection<\/h3>\n<p>The final step in our PHP script is to close the connection we have with our server.<\/p>\n<pre><code class=\"php\">\/\/ close connection\r\nmysql_close($server);<\/code><\/pre>\n<p>With everything put together we have the following PHP script:<\/p>\n<pre><code class=\"html\">&lt;?php\r\n  \/\/ declare database variables\r\n  \/\/ change to the information relevant\r\n  \/\/ to your database\r\n  $username = \"anychart_user\";\r\n  $password = \"password\";  \r\n  $host = \"localhost\";\r\n  $database=\"local_db\";\r\n \r\n  \/\/ connect to database\r\n  $server = mysql_connect($host, $username, $password);\r\n  $connection = mysql_select_db($database, $server);\r\n \r\n  \/\/ perform query\r\n  \/\/ change the query to one relevant to your database\r\n  $myquery = \"\r\n    SELECT  * FROM  `data`\r\n    \";\r\n  $query = mysql_query($myquery);\r\n \r\n  if ( ! $query ) {\r\n    echo mysql_error();\r\n    die;\r\n  }\r\n \r\n  \/\/ encode data to json format\r\n  echo json_encode($data);  \r\n \r\n  \/\/ close connection\r\n  mysql_close($server);\r\n?&gt;<\/code><\/pre>\n<p>The above code connects to our MySQL database, queries it, and returns data which it then exposes in a JSON format. With our data all prepared we can get onto the fun part: <a href=\"https:\/\/www.anychart.com\/blog\/category\/javascript-chart-tutorials\/\">JS charting<\/a>!<\/p>\n<h3>8. Draw Chart<\/h3>\n<p>Once we have our data imported using PHP it is very easy to use with AnyChart. All we need to do is use the same data adapter module we\u2019ve used for importing files. We can do this with the following script:<\/p>\n<pre><code class=\"html\">&lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n<p>Once that is done we simply refer to our\u00a0PHP script when loading the data. Like this:<\/p>\n<pre><code class=\"javascript\">anychart.data.loadJsonFile(\"php\/data.php\", function (data) {\r\n  \/\/ chart code goes here\r\n})\r\n<\/code><\/pre>\n<p>And otherwise, it is business as usual with the entire HTML\/CSS\/JavaScript code below:<\/p>\n<pre><code class=\"html\">&lt;html&gt;\r\n&lt;head&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-base.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;script src=\"https:\/\/cdn.anychart.com\/releases\/8.8.0\/js\/anychart-data-adapter.min.js\"&gt;&lt;\/script&gt;\r\n  &lt;style type=\"text\/css\"&gt;\r\n    html,\r\n    body,\r\n    #container {\r\n      width: 100%;\r\n      height: 100%;\r\n      margin: 0;\r\n      padding: 0;\r\n    }\r\n  &lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n  &lt;div id=\"container\"&gt;&lt;\/div&gt;\r\n  &lt;script&gt;\r\n    anychart.onDocumentReady(function () {\r\n      anychart.data.loadJsonFile(\"php\/data.php\", function (data) {\r\n        \/\/ create a chart and set loaded data\r\n        chart = anychart.bar(data);\r\n        chart.container(\"container\");\r\n        chart.draw();\r\n      });\r\n    });\r\n  &lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>As you can see this approach to handling data for data visualizations is a lot more accessible than you would think. By following these clearly defined steps we can easily use PHP to query our database, retrieve the data as a JSON object before visualizing it using AnyChart.<\/p>\n<p>The example\u00a0of\u00a0connecting a MySQL database\u00a0to\u00a0JS charts created with AnyChart\u00a0described in this tutorial is pretty basic. If you are a more experienced developer and feel ready for more complicated integrations, you may also be interested in checking out <a href=\"https:\/\/www.anychart.com\/technical-integrations\/samples\/php-symfony-mysql-template\/\">PHP, Symfony and MySQL<\/a>, <a href=\"https:\/\/www.anychart.com\/technical-integrations\/samples\/php-laravel-mysql-template\/\">PHP, Laravel and MySQL<\/a>, <a href=\"https:\/\/www.anychart.com\/technical-integrations\/samples\/php-slim-mysql-template\/\">PHP, Slim and MySQL<\/a>, and other\u00a0<a href=\"https:\/\/www.anychart.com\/technical-integrations\/samples\/?filter=php\">PHP integration templates<\/a>,\u00a0as well as <a href=\"https:\/\/www.anychart.com\/technical-integrations\/samples\/?filter=mysql\">MySQL integration templates<\/a> for other languages.<\/p>\n<p>Although we focused on PHP in this tutorial, it must be noted that the other approaches are viable, easy, and may be better suited to your use case. These include using WebSockets, Comet, Ajax, Node.js, and more. If you are in need of tutorials on any of these technologies please feel free to reach out to me and\/or the AnyChart team and I\u2019m sure we can help you out!<\/p>\n<p>You can also add more data in JSON output and <a href=\"https:\/\/docs.anychart.com\/Working_with_Data\/Data_Sets#remapping\" target=\"_blank\" rel=\"nofollow\">map the data<\/a> for more complex charts.<\/p>\n<p><!-- SyntaxHighlighter --><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/default.min.css\"><link rel=\"stylesheet\" href=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/styles\/atom-one-light.min.css\"><script src=\"\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/9.12.0\/highlight.min.js\"><\/script><script>hljs.initHighlightingOnLoad();<\/script><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>When using a charting library like AnyChart, which makes visualizing data so quick and easy, often the most challenging step for beginners is loading data. I think this is largely a result of the fact that while the ways we output the data are quite similar, the input data is commonly very different. The data [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,16,66,18,23,13,279,4],"tags":[53,123,70,71,284,258,282,471,266,1292,880,806,54,256,844,32,55,144,174,36,141,81,57,58,65,56,68,1991,2060,1992,118,30,172],"class_list":["post-11032","post","type-post","status-publish","format-standard","hentry","category-anychart-charting-component","category-anygantt","category-anymap","category-anystock","category-html5","category-javascript","category-javascript-chart-tutorials","category-tips-and-tricks","tag-anychart","tag-anychart-integration-templates","tag-bar-chart","tag-bar-charts","tag-chart-examples","tag-charts","tag-data","tag-data-analysis","tag-data-analytics","tag-data-chart","tag-data-charting","tag-data-charts","tag-data-visualization","tag-data-visualization-examples","tag-data-visualization-tutorial","tag-html5","tag-html5-charts","tag-infographics","tag-integration","tag-javascript","tag-javascript-charting","tag-javascript-charting-library","tag-javascript-charts","tag-js-chart","tag-js-charting","tag-js-charts","tag-js-maps","tag-mysql","tag-mysql-charts","tag-mysql-data-visualization","tag-php-charts","tag-tips-and-tricks","tag-tutorial","wpautop"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>MySQL Database Connection to JS Chart Using PHP<\/title>\n<meta name=\"description\" content=\"JavaScript is client-side. Querying a database requires server-side for security. Learn how to connect MySQL data to a JS chart using PHP.\" \/>\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.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Connecting MySQL Database to JS Chart Using PHP\" \/>\n<meta property=\"og:description\" content=\"JavaScript is client-side. Querying a database requires server-side for security. Learn how to connect MySQL data to a JS chart using PHP.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/\" \/>\n<meta property=\"og:site_name\" content=\"AnyChart News\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AnyCharts\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-04T04:30:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-13T11:01:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png\" \/>\n<meta name=\"author\" content=\"Wayde Herman\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:title\" content=\"Connecting MySQL Database to JS Chart Using PHP\" \/>\n<meta name=\"twitter:description\" content=\"JavaScript is client-side. Querying a database requires server-side for security. Learn how to connect MySQL data to a JS chart using PHP.\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png\" \/>\n<meta name=\"twitter:creator\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:site\" content=\"@AnyChart\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Wayde Herman\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/\"},\"author\":{\"name\":\"Wayde Herman\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/d9447a42182ea80639bfcdde177e0f89\"},\"headline\":\"Connecting MySQL Database to JS Chart Using PHP\",\"datePublished\":\"2020-08-04T04:30:26+00:00\",\"dateModified\":\"2022-08-13T11:01:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/\"},\"wordCount\":1038,\"commentCount\":2,\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png\",\"keywords\":[\"AnyChart\",\"anychart integration templates\",\"bar chart\",\"bar charts\",\"chart examples\",\"charts\",\"data\",\"data analysis\",\"data analytics\",\"data chart\",\"data charting\",\"data charts\",\"Data Visualization\",\"data visualization examples\",\"data visualization tutorial\",\"HTML5\",\"html5 charts\",\"infographics\",\"integration\",\"JavaScript\",\"javascript charting\",\"JavaScript charting library\",\"javascript charts\",\"js chart\",\"js charting\",\"js charts\",\"js maps\",\"MySQL\",\"MySQL charts\",\"MySQL data visualization\",\"php charts\",\"Tips and tricks\",\"tutorial\"],\"articleSection\":[\"AnyChart Charting Component\",\"AnyGantt\",\"AnyMap\",\"AnyStock\",\"HTML5\",\"JavaScript\",\"JavaScript Chart Tutorials\",\"Tips and Tricks\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/\",\"url\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/\",\"name\":\"MySQL Database Connection to JS Chart Using PHP\",\"isPartOf\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png\",\"datePublished\":\"2020-08-04T04:30:26+00:00\",\"dateModified\":\"2022-08-13T11:01:24+00:00\",\"author\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/d9447a42182ea80639bfcdde177e0f89\"},\"description\":\"JavaScript is client-side. Querying a database requires server-side for security. Learn how to connect MySQL data to a JS chart using PHP.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#primaryimage\",\"url\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png\",\"contentUrl\":\"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png\",\"width\":1400,\"height\":767},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.anychart.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Connecting MySQL Database to JS Chart Using PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#website\",\"url\":\"https:\/\/www.anychart.com\/blog\/\",\"name\":\"AnyChart News\",\"description\":\"AnyChart JS Charts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.anychart.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/d9447a42182ea80639bfcdde177e0f89\",\"name\":\"Wayde Herman\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/117ce313e0a18bbfaabbf201e21dfc14c7f633e1d57e32298ace464d25fc21aa?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/117ce313e0a18bbfaabbf201e21dfc14c7f633e1d57e32298ace464d25fc21aa?s=96&r=g\",\"caption\":\"Wayde Herman\"},\"url\":\"https:\/\/www.anychart.com\/blog\/author\/wayde-herman\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MySQL Database Connection to JS Chart Using PHP","description":"JavaScript is client-side. Querying a database requires server-side for security. Learn how to connect MySQL data to a JS chart using PHP.","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.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/","og_locale":"en_US","og_type":"article","og_title":"Connecting MySQL Database to JS Chart Using PHP","og_description":"JavaScript is client-side. Querying a database requires server-side for security. Learn how to connect MySQL data to a JS chart using PHP.","og_url":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/","og_site_name":"AnyChart News","article_publisher":"https:\/\/www.facebook.com\/AnyCharts","article_published_time":"2020-08-04T04:30:26+00:00","article_modified_time":"2022-08-13T11:01:24+00:00","og_image":[{"url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png","type":"","width":"","height":""}],"author":"Wayde Herman","twitter_card":"summary_large_image","twitter_title":"Connecting MySQL Database to JS Chart Using PHP","twitter_description":"JavaScript is client-side. Querying a database requires server-side for security. Learn how to connect MySQL data to a JS chart using PHP.","twitter_image":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png","twitter_creator":"@AnyChart","twitter_site":"@AnyChart","twitter_misc":{"Written by":"Wayde Herman","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#article","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/"},"author":{"name":"Wayde Herman","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/d9447a42182ea80639bfcdde177e0f89"},"headline":"Connecting MySQL Database to JS Chart Using PHP","datePublished":"2020-08-04T04:30:26+00:00","dateModified":"2022-08-13T11:01:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/"},"wordCount":1038,"commentCount":2,"image":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png","keywords":["AnyChart","anychart integration templates","bar chart","bar charts","chart examples","charts","data","data analysis","data analytics","data chart","data charting","data charts","Data Visualization","data visualization examples","data visualization tutorial","HTML5","html5 charts","infographics","integration","JavaScript","javascript charting","JavaScript charting library","javascript charts","js chart","js charting","js charts","js maps","MySQL","MySQL charts","MySQL data visualization","php charts","Tips and tricks","tutorial"],"articleSection":["AnyChart Charting Component","AnyGantt","AnyMap","AnyStock","HTML5","JavaScript","JavaScript Chart Tutorials","Tips and Tricks"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/","url":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/","name":"MySQL Database Connection to JS Chart Using PHP","isPartOf":{"@id":"https:\/\/www.anychart.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#primaryimage"},"image":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#primaryimage"},"thumbnailUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png","datePublished":"2020-08-04T04:30:26+00:00","dateModified":"2022-08-13T11:01:24+00:00","author":{"@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/d9447a42182ea80639bfcdde177e0f89"},"description":"JavaScript is client-side. Querying a database requires server-side for security. Learn how to connect MySQL data to a JS chart using PHP.","breadcrumb":{"@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#primaryimage","url":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png","contentUrl":"https:\/\/www.anychart.com\/blog\/wp-content\/uploads\/2020\/07\/MySQL-database-PHP-JavaScript-Chart-Tutorial.png","width":1400,"height":767},{"@type":"BreadcrumbList","@id":"https:\/\/www.anychart.com\/blog\/2020\/08\/04\/mysql-database-php-js-chart\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.anychart.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Connecting MySQL Database to JS Chart Using PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.anychart.com\/blog\/#website","url":"https:\/\/www.anychart.com\/blog\/","name":"AnyChart News","description":"AnyChart JS Charts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.anychart.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/d9447a42182ea80639bfcdde177e0f89","name":"Wayde Herman","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.anychart.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/117ce313e0a18bbfaabbf201e21dfc14c7f633e1d57e32298ace464d25fc21aa?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/117ce313e0a18bbfaabbf201e21dfc14c7f633e1d57e32298ace464d25fc21aa?s=96&r=g","caption":"Wayde Herman"},"url":"https:\/\/www.anychart.com\/blog\/author\/wayde-herman\/"}]}},"_links":{"self":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/11032","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/comments?post=11032"}],"version-history":[{"count":16,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/11032\/revisions"}],"predecessor-version":[{"id":11074,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/posts\/11032\/revisions\/11074"}],"wp:attachment":[{"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/media?parent=11032"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/categories?post=11032"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.anychart.com\/blog\/wp-json\/wp\/v2\/tags?post=11032"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}