function executemysql($getinfo, $getdumps, $getschema) { //BEGIN GET DB INFO global $getDumpsFrom; global $curdatetime; global $sugar_config; global $progress_bar_percent; global $sod_guid; global $db; if ($db->dbType != "mysql") { if ($getinfo) { sodUpdateProgressBar(MYSQL_INFO_WEIGHT); } if ($getschema) { sodUpdateProgressBar(MYSQL_SCHEMA_WEIGHT); } if ($getdumps) { sodUpdateProgressBar(MYSQL_DUMPS_WEIGHT); } return; } $mysqlInfoDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/MySQL/"); //create directory for table definitions if ($getschema) { $tablesSchemaDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/MySQL/TableSchema/"); } //BEGIN GET MYSQL INFO //make sure they checked the box to get basic info if ($getinfo) { ob_start(); echo "MySQL Version: " . (function_exists('mysqli_get_client_info') ? @mysqli_get_client_info() : @mysql_get_client_info()) . "<BR>"; echo "MySQL Host Info: " . (function_exists('mysqli_get_host_info') ? @mysqli_get_host_info($db->getDatabase()) : @mysql_get_host_info()) . "<BR>"; echo "MySQL Server Info: " . (function_exists('mysqli_get_client_info') ? @mysqli_get_client_info() : @mysql_get_client_info()) . "<BR>"; echo "MySQL Client Encoding: " . (function_exists('mysqli_character_set_name') ? @mysqli_character_set_name($db->getDatabase()) : @mysql_client_encoding()) . "<BR>"; /* Uncomment to get current processes as well echo "<BR>MySQL Processes<BR>"; $res = $db->query('SHOW PROCESSLIST'); echo "<table border=\"1\"><tr><th>Id</th><th>Host</th><th>db</th><th>Command</th><th>Time</th></tr>"; if($db->getRowCount($res) > 0) { while($row = $db->fetchByAssoc($res)) { printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>", $row['Id'], $row['Host'], $row['db'], $row['Command'], $row['Time'] ); } echo "</table><br>"; } else { echo "</table>"; echo "No processes running<br>"; } */ echo "<BR>MySQL Character Set Settings<BR>"; $res = $db->query("show variables like 'character\\_set\\_%'"); echo "<table border=\"1\"><tr><th>Variable Name</th><th>Value</th></tr>"; while ($row = $db->fetchByAssoc($res)) { printf("<tr><td>%s</td><td>%s</td></tr>", $row['Variable_name'], $row['Value']); } echo "</table>"; $content = ob_get_contents(); ob_clean(); $handle = sugar_fopen($mysqlInfoDir . "MySQL-General-info.html", "w"); if (fwrite($handle, $content) === FALSE) { echo "Cannot write to file " . $mysqlInfoDir . "_MySQL-General-info.html<br>"; } fclose($handle); //BEGIN UPDATING PROGRESS BAR sodUpdateProgressBar(MYSQL_INFO_WEIGHT); //END UPDATING PROGRESS BAR } //END GET MYSQL INFO if ($getschema) { //BEGIN GET ALL TABLES SCHEMAS $all_tables = $db->getTablesArray(); global $theme_path; ob_start(); echo "<style>"; echo file_get_contents($theme_path . "style.css"); echo "</style>"; foreach ($all_tables as $tablename) { //setting up table header for each file echo "<table border=\"0\" cellpadding=\"0\" class=\"tabDetailView\">"; echo "<tr>MySQL " . $tablename . " Definitions:</tr>" . "<tr><td class=\"tabDetailViewDL\"><b>Field</b></td>" . "<td class=\"tabDetailViewDL\">Type</td>" . "<td class=\"tabDetailViewDL\">Null</td>" . "<td class=\"tabDetailViewDL\">Key</td>" . "<td class=\"tabDetailViewDL\">Default</td>" . "<td class=\"tabDetailViewDL\">Extra</td></tr>"; $describe = $db->query("describe " . $tablename); while ($inner_row = $db->fetchByAssoc($describe)) { $inner_row = array_values($inner_row); echo "<tr><td class=\"tabDetailViewDF\"><b>" . $inner_row[0] . "</b></td>"; echo "<td class=\"tabDetailViewDF\">" . $inner_row[1] . "</td>"; echo "<td class=\"tabDetailViewDF\">" . $inner_row[2] . "</td>"; echo "<td class=\"tabDetailViewDF\">" . $inner_row[3] . "</td>"; echo "<td class=\"tabDetailViewDF\">" . $inner_row[4] . "</td>"; echo "<td class=\"tabDetailViewDF\">" . $inner_row[5] . "</td></tr>"; } echo "</table>"; echo "<BR><BR>"; } $content = ob_get_contents(); ob_clean(); $handle = sugar_fopen($tablesSchemaDir . "MySQLTablesSchema.html", "w"); if (fwrite($handle, $content) === FALSE) { echo "Cannot write to file " . $tablesSchemaDir . "MySQLTablesSchema.html<br>"; } fclose($handle); //END GET ALL TABLES SCHEMAS //BEGIN UPDATING PROGRESS BAR sodUpdateProgressBar(MYSQL_SCHEMA_WEIGHT); //END UPDATING PROGRESS BAR } if ($getdumps) { //BEGIN GET TABLEDUMPS $tableDumpsDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/MySQL/TableDumps/"); foreach ($getDumpsFrom as $table) { ob_start(); //calling function defined above to get the string for dump echo getFullTableDump($table); $content = ob_get_contents(); ob_clean(); $handle = sugar_fopen($tableDumpsDir . $table . ".html", "w"); if (fwrite($handle, $content) === FALSE) { echo "Cannot write to file " . $tableDumpsDir . $table . "html<br>"; } fclose($handle); } //END GET TABLEDUMPS //BEGIN UPDATING PROGRESS BAR sodUpdateProgressBar(MYSQL_DUMPS_WEIGHT); //END UPDATING PROGRESS BAR } //END GET DB INFO }
function execute_sql($getinfo, $getdumps, $getschema) { //BEGIN GET DB INFO global $getDumpsFrom; global $curdatetime; global $sod_guid; global $db; $sqlInfoDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/{$db->dbName}/"); //create directory for table definitions if ($getschema) { $tablesSchemaDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/{$db->dbName}/TableSchema/"); } //make sure they checked the box to get basic info if ($getinfo) { $info = $db->getDbInfo(); $content = ''; if (!empty($info)) { foreach ($info as $name => $value) { $content .= "{$name}: {$value}<BR>"; } } if (!empty($content)) { file_put_contents($sqlInfoDir . "{$db->dbName}-General-info.html", $content); sodUpdateProgressBar(SQL_INFO_WEIGHT); } } $style = '<style> .tabDetailView { border-bottom:2px solid; border-top:2px solid; margin-bottom:10px; margin-top:2px; border-bottom-color:#ABC3D7; border-top-color:#4E8CCF; } .tabDetailView td table td { border: 0; background: white; } .tabDetailView tr.pagination td { padding-top: 4px; padding-bottom: 4px; border-bottom:1px solid #CBDAE6; } .tabDetailView tr.pagination td table td { border: none; } .tabDetailViewDL { background-color:#F6F6F6; color:#000000; border-bottom:1px solid #CBDAE6; font-size:12px; padding:5px 6px; text-align:left; vertical-align:top; } .tabDetailViewDF { background-color:#FFFFFF; color:#444444; border-bottom:1px solid #CBDAE6; font-size:12px; padding:5px 10px 5px 8px; vertical-align:top; } .listViewThS1 { background:#EBEBED none repeat scroll 0 0; border-color:#CCCCCC -moz-use-text-color; border-style:solid none; border-width:1px medium; font-size:11px; font-weight:bold; padding:4px 5px; text-align:left; } </style>'; if ($getschema) { //BEGIN GET ALL TABLES SCHEMAS $all_tables = $db->getTablesArray(); $contents = $style; foreach ($all_tables as $tablename) { $cols = $db->get_columns($tablename); $indexes = $db->get_indices($tablename); //setting up table header for each file $contents .= array_as_table("{$db->dbName} {$tablename} Definitions:", $cols); $contents .= array_as_table("{$db->dbName} {$tablename} Keys:", $indexes); $contents .= "<BR><BR>"; } file_put_contents($tablesSchemaDir . "{$db->dbName}TablesSchema.html", $contents); //END GET ALL TABLES SCHEMAS //BEGIN UPDATING PROGRESS BAR sodUpdateProgressBar(SQL_SCHEMA_WEIGHT); //END UPDATING PROGRESS BAR } if ($getdumps) { //BEGIN GET TABLEDUMPS $tableDumpsDir = create_cache_directory("diagnostic/" . $sod_guid . "/diagnostic" . $curdatetime . "/{$db->dbName}/TableDumps/"); foreach ($getDumpsFrom as $table) { //calling function defined above to get the string for dump $contents = $style . getFullTableDump($table); file_put_contents($tableDumpsDir . $table . ".html", $contents); } //END GET TABLEDUMPS //BEGIN UPDATING PROGRESS BAR sodUpdateProgressBar(SQL_DUMPS_WEIGHT); //END UPDATING PROGRESS BAR } //END GET DB INFO }