<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css"><!--body { margin-top: 0px;}--></style></head><body>
<table width="200" border="1"><table cellspacing=0 bordercolordark=#FFFFFF width="95%" bordercolorlight=#000000 border=1 align="center" cellpadding="2"> <tr bgcolor="#6b8ba8" style="color:FFFFFF"> <tr> <td width="5%" align="center" valign="bottom" height="19">ID</td> <!--宽度百分比--> <td width="10%" align="center" valign="bottom">店编</td> <td width="20%" align="center" valign="bottom">店名</td> <td width="20%" align="center" valign="bottom">价格</td> </tr><!--</table>
</body></html>--> <!--<?php/*mysql *//* Connect to a MySQL database using driver invocation *///$dsn = 'mysql:dbname=mysql;host=127.0.0.1';//$user = 'root';//$password = '';//try {
// $dbh = new PDO($dsn, $user, $password);//} catch (PDOException $e) { // echo 'Connection failed: ' . $e->getMessage();//}//echo 'mysql连接成功'//?>--> <?php//header("Content-type:text/html;charset=utf-8"); /*解决中文件乱码优先级比 html meta高*///connect to sqlsrv//header('Content-type: text/html; charset=gbk2312');$dsn='sqlsrv:database=s_jxc;server=127.0.0.1,1433';//mysql_set_charset('gb2312',$dsn);$user ='test';$password='test*123';try { $dbh = new PDO($dsn, $user, $password);} catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage();}$sql='select * from login';
$sth = $dbh->query($sql);$result = $sth->fetchAll(); //返回所有结果集//$result = $sth->fetchAll(PDO::FETCH_COLUMN,2); 返回结果集的第几行0是第一行。echo json_encode ($result); //输出json格式Print_r($result);
var_dump($result);//$a=(var_dump($result));//$a = iconv('UTF-8','gbk',$a);//使用Print输出结果
foreach ($sth = $dbh->query($sql) as $row) { print $row['id'] . ",\t"; print $row['user_code'] . ",\t"; print $row['user_name'] . "<\br>"; } //使用Echo输出结果形成表格样式// foreach ($sth = $dbh->query($sql) as $row =>$x) { // echo "<tr>";// echo "<td>".$x['id']."</td>";// //print $x['StoreID'] . ",\t"; //print $x['StoreName'] . "<br />";// echo "<td>".$x['user_code']."</td>";// echo "<td>".$x['user_name']."</td>";// echo "</tr>";// }$sql2='select * from Goods';foreach ($sth2 = $dbh->query($sql2) as $row =>$x) { echo "<tr>"; echo "<td>".$x['id']."</td>"; //print $x['StoreID'] . ",\t"; //print $x['StoreName'] . "<br />"; echo "<td>".$x['goods_code']."</td>"; echo "<td>".$x['goods_name']."</td>"; echo "<td>".$x['goods_sell1']."</td>"; echo "</tr>"; }?>
</table></body></html>