例子,php mysql中创建临时表。
<?php
$link=mysql_connect('localhost','root','') or die(mysql_error());
if($link){
mysql_select_db('test',$link) or die(mysql_error());
mysql_query("set names 'gbk'");
echo "数据库连接已经成功!";
}
//创建临时表
$temp_sql = "create temporary table tmp_query (DEPT_ID int(11) NOT NULL auto_increment PRIMARY KEY,id int(11) default NULL,DEPT_NAME varchar(20) default NULL)";
$temp_query = mysql_query($temp_sql)or die(mysql_error());
$sql="insert into tmp_query(DEPT_ID,DEPT_NAME) select DEPT_ID,DEPT_NAME from department ";
mysql_query($sql) or die(mysql_error());
$sql="select * from tmp_query";
$query1=mysql_query($sql)or die(mysql_error());
echo mysql_num_rows($query1);
www.jb200.com
while($rs=mysql_fetch_array($query1)){
echo $rs['DEPT_ID']." ".$rs['DEPT_NAME']."<br>";
}
?>