{"id":232886,"date":"2023-01-30T09:45:00","date_gmt":"2023-01-30T06:45:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=232886"},"modified":"2023-02-06T11:09:35","modified_gmt":"2023-02-06T08:09:35","slug":"come-stampare-il-riepilogo-della-tabella-mysql-utilizzando-php","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/it\/come-stampare-il-riepilogo-della-tabella-mysql-utilizzando-php\/","title":{"rendered":"Come stampare il riepilogo della tabella MySQL utilizzando PHP?"},"content":{"rendered":"<p>La tabella <a href=\"https:\/\/helloacm.com\/how-to-generate-100k-test-data-to-mysql-database\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">MySQL<\/a> ha un comando <strong>Show Table Status<\/strong> che stampa un riepilogo della tabella, ma contiene molte informazioni su tutte le tabelle nel database corrente (per cambiare database, usa &#8216;use database_name&#8217;), che non \u00e8 cos\u00ec facile da usare.<\/p>\n<p>Quello che vogliamo sapere \u00e8 la dimensione dei dati e la dimensione dell&#8217;indice, \u00e8 possibile utilizzare il seguente script <a href=\"https:\/\/helloacm.com\/the-php-bing-wallpaper-bot-crawler\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">PHP per stampare tali informazioni.<\/a><\/p>\n<pre><code>&lt;?php\n\u00a0 require('conn.php'); \/\/ connect your database using e.g. $connection = mysqli_connect(...)\n\u00a0 $query = \"show table status\";\n\u00a0 $result = mysqli_query($connection, $query);\n\u00a0 $ds = 0;\n\u00a0 $is = 0;\n\u00a0 echo \"&lt;table style='text-align:left;width:100%'&gt;\";\n\u00a0 echo \"&lt;tr \u00a0style='background:blue;color:yellow;'&gt;&lt;th&gt;Name&lt;\/th&gt;&lt;th&gt;Data&lt;\/th&gt;&lt;th&gt;Index&lt;\/th&gt;&lt;\/tr&gt;\";\n\u00a0 function format($c) {\n\u00a0 \u00a0 return (round($c \/ 1024, 2)). 'KB';\n\u00a0 }\n\u00a0 while ($row = mysqli_fetch_assoc($result)) {\n\u00a0 \u00a0 echo \"&lt;tr&gt;&lt;th&gt;\". ($row['Name']). '&lt;\/th&gt;';\n\u00a0 \u00a0 echo \"&lt;th&gt;\". format($row['Data_length']). \"&lt;\/th&gt;\";\n\u00a0 \u00a0 echo \"&lt;th&gt;\". format($row['Index_length']). \"&lt;\/th&gt;\";\n\u00a0 \u00a0 $ds += $row['Data_length'];\n\u00a0 \u00a0 $is += $row['Index_length'];\n\u00a0 \u00a0 echo \"&lt;\/tr&gt;\";\n\u00a0 }\n\u00a0 echo \"&lt;tr style='background:lightblue;'&gt;\";\n\u00a0 echo \"&lt;th&gt;\". format($ds + $is). \"&lt;\/th&gt;&lt;th&gt;\". format($ds). \"&lt;\/th&gt;&lt;th&gt;\". format($is). \"&lt;\/th&gt;\";\n\u00a0 echo \"&lt;\/tr&gt;&lt;\/table&gt;\";<\/code><\/pre>\n<p>Ecco un esempio dell&#8217;utilizzo da un tipico database <a href=\"https:\/\/wordpress.mediadoma.com\/it\/come-aggiungere-disqus-se-i-commenti-sono-chiusi-in-wordpress\/\" title=\"wordpress .\">wordpress .<\/a> Formattiamo la dimensione usando KB. In questo modo, puoi tenere traccia dell&#8217;utilizzo della tabella di volta in volta. Puoi anche modificare l&#8217;elegante CSS nel codice sopra per formattare l&#8217;output.<\/p>\n<p>mysql-show-table-status-in-php-example<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">Fonte di registrazione:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/helloacm.com\" class=\"external external_icon\">helloacm.com<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Come stampare il riepilogo della tabella MySQL utilizzando PHP?<\/p>\n","protected":false},"author":1,"featured_media":224526,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[918,896,804,720],"tags":[1168],"class_list":["post-232886","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-altro","category-codice","category-php-6","category-sviluppatore","tag-affiai-it"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/232886","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/comments?post=232886"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/posts\/232886\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media\/224526"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/media?parent=232886"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/categories?post=232886"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/it\/wp-json\/wp\/v2\/tags?post=232886"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}