<?php backup_tables('localhost','userid','password','dbname');
/* backup the db OR just a table */
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);
//get all of the tables
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
print_r($tables);
}
else
{
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
//save file
$handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+');
fwrite($handle,$return);
fclose($handle);
}
?>
Secure file download in PHP, Security question PHP, PHP MYSQL Interview Question -Books download - PHP solutions guidelines queries update, phpmysqlquestion
Friday, March 27, 2009
Thursday, March 12, 2009
mysql_connect vs. mysql_pconnect
pconnects are expensive in RAM. Make sure you have enough to handle all the children you need and you're ok. total size of an average mysql child process, then subtract the amount of shared memory it uses and you have an approximate delta. Typical mysql is depending on the query you are running, are anywhere from 1 to 10 megs.
Friday, March 6, 2009
Displaying PHP SessionID
<?php
session_start();
?>
</HEAD>
<style type="text/css">
<!--
.style2 {color: #0066FF}
.style3 {
color: #009933;
font-weight: bold;
}
.style5 {color: #0066FF; font-weight: bold; }
-->
</style>
<BODY>
<strong>Displaying PHP SessionID by Tutorial Guide by http://www.phpmysqlquestion.blogspot.com/
</strong>
<h1 align="center" class="style2">Your PHPSESSID is: <?php echo session_id(); ?></h1>
<span class="style5">NOTE</span>: If you don't see a session id in tbe blue header above, hit <span
class="style3">REFRESH</span> on your browser <br />
<br />
<div align="center">Turotial by <a
href="http://www.phpmysqlquestion.blogspot.com/">http://www.phpmysqlquestion.blogspot.com/</a></div>
<p>
</BODY>
</HTML>
session_start();
?>
</HEAD>
<style type="text/css">
<!--
.style2 {color: #0066FF}
.style3 {
color: #009933;
font-weight: bold;
}
.style5 {color: #0066FF; font-weight: bold; }
-->
</style>
<BODY>
<strong>Displaying PHP SessionID by Tutorial Guide by http://www.phpmysqlquestion.blogspot.com/
</strong>
<h1 align="center" class="style2">Your PHPSESSID is: <?php echo session_id(); ?></h1>
<span class="style5">NOTE</span>: If you don't see a session id in tbe blue header above, hit <span
class="style3">REFRESH</span> on your browser <br />
<br />
<div align="center">Turotial by <a
href="http://www.phpmysqlquestion.blogspot.com/">http://www.phpmysqlquestion.blogspot.com/</a></div>
<p>
</BODY>
</HTML>
Subscribe to:
Posts (Atom)
How to solve mysql ERROR 1118 (42000) Row size too large
I had this issue with MYSQL 5.7 . The following worked althoug...
-
PHP has an SSH2 library which provides access to resources (shell, remote exec, tunneling, file transfer) on a remote ma...
-
Which pillar of the AWS Well-Architected Framework recommends maintaining infrastructure as code? Operational Excellence Which of the foll...
-
Introduction to PHP PDO (PHP Data Objects) 1. What is PDO 2. What Databases does PDO support 3. Where do I begin? 4. Connect to ...