$ su
# yum install php-mysql
# service httpd stop
# service httpd start
# service mysqld stop
# service mysqld start
2.以下のファイルを作成し,/var/www/html以下に配置
index.php
<HTML> <HEAD> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE>SA2011 sample</TITLE> <STYLE TYPE="text/css"> <!-- .table1 { width: 600px; border-collapse: collapse; border: 1px #111111 solid; } .table1 TD { border: 1px #111111 solid; } --> </STYLE> </HEAD> <BODY> <H1>SA2011 SAMPLE PAGE</H1> <br /> <a href='status.php?name="sato"&pass="******"'>XML SAMPLE</a> <?php $db_user = "root"; $db_password = "******"; $db_name = "sample"; $db_table_name = "users"; $db_host = "localhost"; $db = mysql_connect($db_host,$db_user,$db_password); mysql_select_db($db_name,$db); $strsql = "SET CHARACTER SET UTF8"; mysql_query($strsql,$db); $str_sql = "select * from ".$db_table_name; $rs = mysql_query($str_sql,$db); $num = mysql_num_fields($rs); print("<table CLASS='table1'><tr><th colspan=7>Registered User List</th></tr>"); print("<tr>"); for ($i=0;$i<$num;$i++){ print("<td><b>".mysql_field_name($rs,$i)."</b></td>"); } print("</tr>"); while($row=mysql_fetch_array($rs)){ print("<tr>"); for($j=0;$j<$num;$j++){ print("<td>".$row[$j]."</td>"); } print("</tr>"); } print("</table>"); mysql_free_result($rs); mysql_close($db); ?> </BODY> </HTML>
status.php
<?php $db_user = "root"; $db_password = "******"; $db_name = "sample"; $db_table_name = "users"; $db_host = "localhost"; //create xml header('Content-type: text/xml; charset=utf-8'); echo '<?xml version="1.0"?><sample>'; $user_name = null; $user_pass = null; if(isset($_GET['name'])) { $user_name = $_GET['name']; $user_pass = $_GET['pass']; $con = mysql_connect($db_host,$db_user,$db_password) or die("error!"); mysql_select_db($db_name,$con) or die("DB is not exist"); $strsql = "SET CHARACTER SET UTF8"; mysql_query($strsql,$con); $strsql = "SELECT money, item, kana, studentId FROM ".$db_table_name." WHERE name = $user_name AND pass = $user_pass;"; $res = mysql_query($strsql,$con); while ($item = mysql_fetch_array($res)) { print "<user_status><money>".$item[0]."</money><item>".$item[1]."</item><kana>".$item[2]."</kana><studentId>".$item[3]."</studentId></user_status>"; } mysql_close($con); } echo '</sample>'; ?>
0 件のコメント:
コメントを投稿