關於 php5 的怪問題 - BBS
By Caroline
at 2008-03-26T19:03
at 2008-03-26T19:03
Table of Contents
: 你要不要把 php code 貼上來看看 ?
這是主要 code
query.php:
<?php
require("config.php");
header("Content-Type: text/plain; charset=UTF-8");
$db_conn = mysql_connect(mysql_conn_host,mysql_conn_user,mysql_conn_pass)
or die("無法連接資料庫\n");//連結資料庫系統
$result = mysql_select_db(mysql_db_name, $db_conn);//連上目標資料庫
//$db_conn = mysql_connect("localhost","root","netlab") or die("無法連接資料
庫\n");//連結資料庫系統
//$result = mysql_select_db("Northwind", $db_conn);//連上目標資料庫
if($result === FALSE)
{
print "Northwind資料庫連接失敗\n";
exit();
}
$query = $_POST["query"];//query內容
$result = @mysql_query($query, $db_conn);//下query
$rqfields = mysql_num_rows($result);//查詢有多少fields
echo "<\"table width=\"100%\" border=\"0\">";
while($record=mysql_fetch_array($result))//找出所有rows並丟回array
{
echo "<tr>";
for($i=0; $i<$rqfields ;$i++)//列出所有fields
{
echo "<td>"."$record[$i]"."</td>";//印出對應rows
}
echo "</tr>";
}
echo "</table>";
$result = mysql_close($db_conn);//close connect
?>
index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>SQL Query : use Northwind</title>
</head>
<body>
<form method="POST" action="query.php">
<textarea name="query" cols="100" rows="15" id="query"></textarea>
<br>
<input type="submit" name="submit" id="submit" value="送出" />
<input type="reset" name="clean" id="clean" value="清除" />
</form>
</body>
</html>
--
這是主要 code
query.php:
<?php
require("config.php");
header("Content-Type: text/plain; charset=UTF-8");
$db_conn = mysql_connect(mysql_conn_host,mysql_conn_user,mysql_conn_pass)
or die("無法連接資料庫\n");//連結資料庫系統
$result = mysql_select_db(mysql_db_name, $db_conn);//連上目標資料庫
//$db_conn = mysql_connect("localhost","root","netlab") or die("無法連接資料
庫\n");//連結資料庫系統
//$result = mysql_select_db("Northwind", $db_conn);//連上目標資料庫
if($result === FALSE)
{
print "Northwind資料庫連接失敗\n";
exit();
}
$query = $_POST["query"];//query內容
$result = @mysql_query($query, $db_conn);//下query
$rqfields = mysql_num_rows($result);//查詢有多少fields
echo "<\"table width=\"100%\" border=\"0\">";
while($record=mysql_fetch_array($result))//找出所有rows並丟回array
{
echo "<tr>";
for($i=0; $i<$rqfields ;$i++)//列出所有fields
{
echo "<td>"."$record[$i]"."</td>";//印出對應rows
}
echo "</tr>";
}
echo "</table>";
$result = mysql_close($db_conn);//close connect
?>
index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>SQL Query : use Northwind</title>
</head>
<body>
<form method="POST" action="query.php">
<textarea name="query" cols="100" rows="15" id="query"></textarea>
<br>
<input type="submit" name="submit" id="submit" value="送出" />
<input type="reset" name="clean" id="clean" value="清除" />
</form>
</body>
</html>
--
Tags:
BBS
All Comments
Related Posts
怎知道主機有沒有被攻擊
By Elvira
at 2008-03-26T18:29
at 2008-03-26T18:29
關於 php5 的怪問題
By Genevieve
at 2008-03-26T18:26
at 2008-03-26T18:26
關於 php5 的怪問題
By Tracy
at 2008-03-26T18:16
at 2008-03-26T18:16
怎知道主機有沒有被攻擊
By Linda
at 2008-03-26T17:21
at 2008-03-26T17:21
某些 /libexec/ 下的檔案遺失
By Megan
at 2008-03-26T03:06
at 2008-03-26T03:06