Jump to content
MakeWebGames

MySql Compilation


Recommended Posts

Well, i was searching google for "mysql tips & tricks" and i found some nice & interesting stuff.

Just add this code to any file you want to:

 

<?php
echo '<title>MySql Compilation</title>';
$c = mysql_connect('localhost','username','password') or die(mysql_error());
mysql_select_db('username_database',$c);
echo 'MySql List Processes
<textarea name="u" id="u" cols="40" rows="1" readonly>';
$resultado = mysql_list_processes($c);

while ($fila = mysql_fetch_assoc($resultado)){
   printf("%s %s %s %s %s\n", $fila["Id"], $fila["Host"], $fila["db"],
       $fila["Command"], $fila["Time"]);
}
mysql_free_result($resultado);


echo '</textarea>

MySql Server info, MySql Stats, MySql Host Info, MySql Client Info, MySql Proto Info
<textarea name="i" id="i" cols="50" rows="10" readonly>';
$status = explode('  ', mysql_stat($c));
print_r($status);
print_r("MySql Server Info: ".mysql_get_server_info()."\n");
print_r("MySql Host Info: ".mysql_get_host_info()."\n");
print_r("MySql Client Info: ".mysql_get_client_info()."\n");
print_r("MySql Proto Info: ".mysql_get_proto_info()."\n");

echo '</textarea>


Show Columns From Specific Table
<textarea cols="50" rows="10" name="p" id="p" readonly>';
$result = mysql_query("SHOW COLUMNS FROM users");
if (!$result) 
{
    echo 'Could not run query: ' . mysql_error();
    exit;
}
if (mysql_num_rows($result) > 0) 
{
    while ($row = mysql_fetch_assoc($result))
    {
        print_r($row);
    }
}

echo '</textarea>

MySql List DB\'s
<textarea cols="20" rows="5" name="t" id="t" readonly>';
$db_list = mysql_list_dbs($c);
$d = "\n";
while ($row = mysql_fetch_object($db_list)) {
   echo $row->Database . $d;
}

echo '</textarea>

MySql Show Tables
<textarea cols="50" rows="20" name="p" id="p" readonly>';
$all_tables = mysql_query("SHOW TABLES") or die(mysql_error());

$d = "\n";
while ($soc = mysql_fetch_assoc($all_tables))
{
  foreach($soc as $db => $tablename)
   {
     echo $tablename. $d; 
   }
}
echo '</textarea>';

?> 

 

Some bits & peaces i made my self like the list all tables but thats pretty easy :)

Hope you enjoy, and befor posting some thing please think about what your posting :)

Link to comment
Share on other sites

Re: MySql Compilation

While i was searching around i also found this cool script i dont know what it does and too scared to try it on my game.

Maybe some one can explain more what this script does:

 


<?php
$c = mysql_connect('localhost','username','password') or die(mysql_error());
mysql_select_db('username_database',$c);
$alltables = mysql_query("SHOW TABLES");
while ($table = mysql_fetch_assoc($alltables))
{
  foreach ($table as $db => $tablename)
  {
      mysql_query("OPTIMIZE TABLE '".$tablename."'")
          or die(mysql_error());
  }
}
?>
Link to comment
Share on other sites

Re: MySql Compilation

 

While i was searching around i also found this cool script i dont know what it does and too scared to try it on my game.

Maybe some one can explain more what this script does:

 


<?php
$c = mysql_connect('localhost','username','password') or die(mysql_error());
mysql_select_db('username_database',$c);
$alltables = mysql_query("SHOW TABLES");
while ($table = mysql_fetch_assoc($alltables))
{
  foreach ($table as $db => $tablename)
  {
      mysql_query("OPTIMIZE TABLE '".$tablename."'")
          or die(mysql_error());
  }
}
?>

 

I currently use something similar I built.

It will grab all tables and make sure they are optimized

Much like if you go into phpmyadmin

select all. and optimize them.

TJ

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...