首页上一页 1 下一页尾页 3 条记录 1/1页
PHP入门到精通第19章PDO数据抽象层连接sql server总是提醒查询超时,下面附代码
发表在PHP图书答疑
2014-09-19
是否精华
是
否
版块置顶:
是
否
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>项目选择</title>
<style type="text/css">
<!--
.STYLE1 {font-size: small}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="460" border="1" align="center">
<caption align="top">
ERP订单
</caption>
<tr>
<th width="24" bgcolor="#66FFFF" scope="col"> </th>
<th width="90" bgcolor="#66FFFF" scope="col"><div align="center" class="STYLE1">项目编号</div></th>
<th width="218" bgcolor="#66FFFF" scope="col"><div align="center" class="STYLE1">项目名称</div></th>
<th width="55" bgcolor="#66FFFF" scope="col"><div align="center" class="STYLE1">负责人</div></th>
<th width="39" bgcolor="#66FFFF" scope="col"><div align="center" class="STYLE1">数量</div></th>
</tr>
<?php
$dbms='mssql'; //数据库类型 ,对于开发者来说,使用不同的数据库,只要改这个,不用记住那么多的函数
$host='local'; //数据库主机名
$dbName='DSB'; //使用的数据库
$user='sa'; //数据库连接用户名
$pass=''; //对应的密码
$dsn="$dbms:host=$host;dbname=$dbName";
try {
$pdo = new PDO($dsn, $user, $pass); //初始化一个PDO对象,就是创建了数据库连接对象$pdo
$query="select IBA001 AS ID ,DFA002 AS NAME,DBA002 AS MAN,SUM(IBB006) AS NUMBER from DCSIBA
LEFT JOIN TPADFA ON DFA001 = IBA004
LEFT JOIN TPADBA ON DBA001 = IBA005
LEFT JOIN DCSIBB ON IBB001 = IBA001
GROUP BY IBA001,DFA002,DBA00"; //定义SQL语句
$result=$pdo->prepare($query); //准备查询语句
$result->execute(); //执行查询语句,并返回结果集
while($res=$result->fetch(PDO::FETCH_ASSOC)){ //while循环输出查询结果集,并且设置结果集的为关联索引
?>
<tr>
<td align="center" valign="middle"><input type="radio" name="radiobutton" value="radiobutton" id="radiobutton" />
<label for="radiobutton"></label></td>
<td height="22" align="center" valign="middle"><?php echo $res['ID'];?></td>
<td align="center" valign="middle"><?php echo $res['NAME'];?></td>
<td align="center" valign="middle"><?php echo $res['MAN'];?></td>
<td align="center" valign="middle"><?php echo $res['NUMBER'];?></td>
</tr>
<?php
}
} catch (PDOException $e) {
die ("Error!: " . $e->getMessage() . "<br/>");
}
?>
</table>
<div align="center"></div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>项目选择</title>
<style type="text/css">
<!--
.STYLE1 {font-size: small}
-->
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<table width="460" border="1" align="center">
<caption align="top">
ERP订单
</caption>
<tr>
<th width="24" bgcolor="#66FFFF" scope="col"> </th>
<th width="90" bgcolor="#66FFFF" scope="col"><div align="center" class="STYLE1">项目编号</div></th>
<th width="218" bgcolor="#66FFFF" scope="col"><div align="center" class="STYLE1">项目名称</div></th>
<th width="55" bgcolor="#66FFFF" scope="col"><div align="center" class="STYLE1">负责人</div></th>
<th width="39" bgcolor="#66FFFF" scope="col"><div align="center" class="STYLE1">数量</div></th>
</tr>
<?php
$dbms='mssql'; //数据库类型 ,对于开发者来说,使用不同的数据库,只要改这个,不用记住那么多的函数
$host='local'; //数据库主机名
$dbName='DSB'; //使用的数据库
$user='sa'; //数据库连接用户名
$pass=''; //对应的密码
$dsn="$dbms:host=$host;dbname=$dbName";
try {
$pdo = new PDO($dsn, $user, $pass); //初始化一个PDO对象,就是创建了数据库连接对象$pdo
$query="select IBA001 AS ID ,DFA002 AS NAME,DBA002 AS MAN,SUM(IBB006) AS NUMBER from DCSIBA
LEFT JOIN TPADFA ON DFA001 = IBA004
LEFT JOIN TPADBA ON DBA001 = IBA005
LEFT JOIN DCSIBB ON IBB001 = IBA001
GROUP BY IBA001,DFA002,DBA00"; //定义SQL语句
$result=$pdo->prepare($query); //准备查询语句
$result->execute(); //执行查询语句,并返回结果集
while($res=$result->fetch(PDO::FETCH_ASSOC)){ //while循环输出查询结果集,并且设置结果集的为关联索引
?>
<tr>
<td align="center" valign="middle"><input type="radio" name="radiobutton" value="radiobutton" id="radiobutton" />
<label for="radiobutton"></label></td>
<td height="22" align="center" valign="middle"><?php echo $res['ID'];?></td>
<td align="center" valign="middle"><?php echo $res['NAME'];?></td>
<td align="center" valign="middle"><?php echo $res['MAN'];?></td>
<td align="center" valign="middle"><?php echo $res['NUMBER'];?></td>
</tr>
<?php
}
} catch (PDOException $e) {
die ("Error!: " . $e->getMessage() . "<br/>");
}
?>
</table>
<div align="center"></div>
</form>
</body>
</html>