初学者的困惑:MySql怎样用在PHP中? 可以用phpMyadmin 等工具来进行管理呀!用google 搜一下吧,可以找到很多工具的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 好多兄弟问这个问题。我用php写了一个数据导出程序。只要提供数据表明称,就可以导出表结构和数据了。如果你要上传,只需要把到处的文件上传执行就行了!<? define("AUTO_QUOTE",get_magic_quotes_gpc()); # configuration $db_name = "buybook"; $file = "d:/mysqlbak/bb.sql"; # bakup path and file $create_tables = true; # add "CREATE TABLE" syntax at the begining of the script $host = "localhost"; $user = "root"; $pass = ""; $database = "buybook"; function _create_table($table){ $tabledump = "DROP TABLE IF EXISTS $table;\n"; $tabledump .= "CREATE TABLE $table (\n"; $firstfield = 1; $result = mysql_query("SHOW FIELDS FROM $table"); //0->Field //1->Type //2->Null //3->Default //4->Extra while ($field = mysql_fetch_array($result)) { if (!$firstfield) { $tabledump .= ",\n"; } else { $firstfield = 0; } $tabledump .= "\t$field[0] $field[1]"; if ($field[2] == "YES") { $tabledump .= " "; } else { $tabledump .= " NOT NULL"; } if (!empty($field["3"])) { $tabledump .= " default '$field[3]'"; } if ($field[4] != "") { $tabledump .= " $field[4]"; } } mysql_free_result($result); $result1 = mysql_query("SHOW KEYS FROM $table"); while ($key = mysql_fetch_array($result1)) { $kname = $key['Key_name']; if ($kname != "PRIMARY" and $key['Non_unique'] == 0) { $kname="UNIQUE|$kname"; } if(!is_array($index[$kname])) { $index[$kname] = array(); } $index[$kname][] = $key['Column_name']; } mysql_free_result($result1); while(list($kname, $columns) = @each($index)) { $tabledump .= ",\n"; $colnames = implode($columns, ","); if($kname == "PRIMARY") { $tabledump .= "\tPRIMARY KEY ($colnames)"; } else { if (substr($kname,0,6) == "UNIQUE") { $kname = substr($kname,7); } $tabledump .= "\tKEY $kname ($colnames)"; } } $tabledump .= "\n);\n\n"; $result2 = mysql_query("SELECT * FROM $table"); $numfields = mysql_num_fields($result2); $numrows = mysql_num_rows($result2); while ($row = mysql_fetch_row($result2)) { $comma = ""; $tabledump .= "INSERT INTO $table VALUES("; for($i = 0; $i < $numfields; $i++) { $tabledump .= $comma."'".mysql_escape_string($row[$i])."'"; $comma = ","; } $tabledump .= ");\n"; } $tabledump .= "\n"; mysql_free_result($result2); return $tabledump; } function _get_tables($db){ $sql = mysql_query("SHOW TABLES FROM ".$db); $i=0; while($row = mysql_fetch_assoc($sql)) { list($tables[$i++]) = array_values($row); } return $tables; } function _comments(){ $bomb = "/*************************************\n"; $bomb .= "# Useing php for mysql tables dump...\n"; $bomb .= "# Code by bombshell\n"; $bomb .= "# Date 2003-05-06\n"; $bomb .= "************************************/\n"; return $bomb; } mysql_connect($host,$user,$pass); mysql_select_db($database); #header("Content-type: text/plain\r\n"); $tables = _get_tables("buybook"); $add_table = ""; if($create_tables == true){ foreach($tables as $tab){ $addtable .= _create_table($tab); } $add_table .= "\n\n"; }if(!empty($file)){ $fp = fopen($file,"w"); fwrite($fp,_comments()); fwrite($fp,$addtable); fclose($fp); echo "MySQL database saved into file ".$file; }else{ echo $addtable; foreach($tables as $tab){ echo _dump_table($tab); } echo _comments(); } ?> 这个事务怎么处理 【求助】数据库数据取出出现乱码 mysql 三张表,主外键关系维护 mysql5.0 not null不起约束作用 如何解决mysql在win2000下不登录或锁定计算机时无法工作的问题 MySQL新手急问 在线等待:怎样建立初始的MySQL权限(os:windows) 问:怎样列出某个字段中不同的值? 在Linux7.3上安装PostgreSql7.3.4是,执行./configure出错,求助! mysqli query删除语句成功失败都返回是1 一存储过程默认参数问题 最新更新 MySQL、InnoDB 中文参考手册
<?
define("AUTO_QUOTE",get_magic_quotes_gpc());
# configuration
$db_name = "buybook";
$file = "d:/mysqlbak/bb.sql"; # bakup path and file
$create_tables = true; # add "CREATE TABLE" syntax at the begining of the script
$host = "localhost";
$user = "root";
$pass = "";
$database = "buybook"; function _create_table($table)
{
$tabledump = "DROP TABLE IF EXISTS $table;\n";
$tabledump .= "CREATE TABLE $table (\n"; $firstfield = 1; $result = mysql_query("SHOW FIELDS FROM $table");
//0->Field
//1->Type
//2->Null
//3->Default
//4->Extra
while ($field = mysql_fetch_array($result))
{
if (!$firstfield)
{
$tabledump .= ",\n";
}
else
{
$firstfield = 0;
}
$tabledump .= "\t$field[0] $field[1]";
if ($field[2] == "YES")
{
$tabledump .= " ";
}
else
{
$tabledump .= " NOT NULL";
} if (!empty($field["3"]))
{
$tabledump .= " default '$field[3]'";
}
if ($field[4] != "")
{
$tabledump .= " $field[4]";
}
}
mysql_free_result($result);
$result1 = mysql_query("SHOW KEYS FROM $table");
while ($key = mysql_fetch_array($result1))
{
$kname = $key['Key_name'];
if ($kname != "PRIMARY" and $key['Non_unique'] == 0)
{
$kname="UNIQUE|$kname";
}
if(!is_array($index[$kname]))
{
$index[$kname] = array();
}
$index[$kname][] = $key['Column_name'];
}
mysql_free_result($result1); while(list($kname, $columns) = @each($index))
{
$tabledump .= ",\n";
$colnames = implode($columns, ","); if($kname == "PRIMARY")
{
$tabledump .= "\tPRIMARY KEY ($colnames)";
}
else
{
if (substr($kname,0,6) == "UNIQUE")
{
$kname = substr($kname,7);
} $tabledump .= "\tKEY $kname ($colnames)"; }
} $tabledump .= "\n);\n\n";
$result2 = mysql_query("SELECT * FROM $table");
$numfields = mysql_num_fields($result2);
$numrows = mysql_num_rows($result2);
while ($row = mysql_fetch_row($result2))
{
$comma = "";
$tabledump .= "INSERT INTO $table VALUES(";
for($i = 0; $i < $numfields; $i++)
{
$tabledump .= $comma."'".mysql_escape_string($row[$i])."'";
$comma = ",";
}
$tabledump .= ");\n";
}
$tabledump .= "\n";
mysql_free_result($result2);
return $tabledump;
}
function _get_tables($db)
{
$sql = mysql_query("SHOW TABLES FROM ".$db);
$i=0;
while($row = mysql_fetch_assoc($sql))
{
list($tables[$i++]) = array_values($row);
}
return $tables;
}
function _comments()
{
$bomb = "/*************************************\n";
$bomb .= "# Useing php for mysql tables dump...\n";
$bomb .= "# Code by bombshell\n";
$bomb .= "# Date 2003-05-06\n";
$bomb .= "************************************/\n";
return $bomb;
} mysql_connect($host,$user,$pass);
mysql_select_db($database);
#header("Content-type: text/plain\r\n"); $tables = _get_tables("buybook"); $add_table = "";
if($create_tables == true){
foreach($tables as $tab){
$addtable .= _create_table($tab);
}
$add_table .= "\n\n";
}if(!empty($file))
{
$fp = fopen($file,"w");
fwrite($fp,_comments());
fwrite($fp,$addtable);
fclose($fp);
echo "MySQL database saved into file ".$file;
}else{
echo $addtable;
foreach($tables as $tab){
echo _dump_table($tab);
}
echo _comments();
}
?>