【发布时间】:2016-06-15 08:29:22
【问题描述】:
我正在做一个小项目。目的是从我的 MS SQL Express 服务器 2008 接收数据到网页。这一切都很好。我使用 ODBC 连接扩展来执行此操作。我已经设置了一个呼叫者,所以你可以选择你想要接收的日期。但就像我说的,这一切都很好。
我的问题: 我想从不同的 SQL 服务器获取数据。一共3个。我的 sql 语句在每个 sql server 上都是一样的。唯一需要更改的是连接字符串和数据库。在这里你会找到我的 PHP 代码。我将使用 php ro 中的 $_POST 从我的表单接收操作。
在 HTML 中,您可以看到我使用了一个选择选项。每当我选择“Grimbergen”时,连接字符串必须更改为 $connection_string = $grim;当我选择“Gent”时,连接字符串必须更改
$connection_string = $topo;
if (isset($_POST['knop'])) {
$user = 'someuser';
$pass = 'somepassword';
$grim = 'DRIVER={SQL Server};SERVER=10.10.10.10\UNIWIN_GRIM;DATABASE=UniCla';
$topo = 'DRIVER={SQL Server};SERVER=10.10.10.10\UNIWIN_TOPO;DATABASE=UniCla';
$connection_string = ; //don't know how i get this with $_POST!!!
echo $connection_string;
$connection = odbc_connect( $connection_string, $user, $pass );
if (odbc_error()) {
echo odbc_errormsg($connection);
}
$connection = odbc_connect( $connection_string, $user, $pass );
// you must set the connection first
if (odbc_error()) {
echo odbc_errormsg($connection);
}
$bdate= $_POST['bdate'];
$edate= $_POST['edate'];
$grim_s = 'SRGR';
$topo_s = 'SRTO';
$stmt = "SELECT String1, String3, String13, String15, String4, String8, InOut, Weight1, Date1, Time1, Weight2, Date2, Time2, Nett FROM dbo.Move WHERE Date1 BETWEEN '$bdate' AND '$edate' AND String13='$grim_s' ORDER BY Date1 desc;";
$result = odbc_exec($connection, $stmt);
还有 HTML:
<form enctype="multipart/form-data" method="post" name="formulier" id="formulier" action="">
<div>
<h4>Site</h4>
<p>
<select name="place" id="place" class="form-control" >
<option value="grim">Grimbergen</option>
<option value="gent">Gent</option>
</select>
</p>
</div>
<div>
<h4>Begin Date</h4>
<input name="bdate" id="picker1" class="form-control" type="text">
</div>
<div>
<h4>End Date</h4>
<input name="edate" id="picker2" class="form-control" type="text">
</div>
<br>
<div>
<button type="submit" value="login" class="btn btn-info btn-fill pull-right" name="knop" id="knop">Submit</button>
</div>
</form>
【问题讨论】:
-
你的意思是从不同的数据库中获取数据,bur相同的查询?
-
是的。查询是一样的。
-
好吧,grim 和 gent 是数据库还是告诉你的数据库名称
-
当您在 HTML 中选择 Grimbergen 时,连接字符串必须更改为“DRIVER={SQL Server};SERVER=10.10.10.10\UNIWIN_GRIM;DATABASE=UniCla”。当您在 HTML 中选择 Gent 时,连接字符串必须是 'DRIVER={SQL Server};SERVER=10.10.10.10\UNIWIN_TOPO;DATABASE=UniCla'