직장에서 작은 프로젝트를 진행하고 있습니다. 의도는 내 MS SQL Express 서버 2008에서 웹 페이지로 데이터를받는 것입니다. 이것은 모두 정상적으로 작동합니다. 이렇게하려면 ODBC 연결 확장을 사용합니다. 나는 발신자를 설정 했으므로 수신 할 날짜 사이를 선택할 수 있습니다. 하지만 제가 말했듯이, 이것은 모두 잘 작동합니다.여러 옵션 선택 sql 및 ph
내 문제 : 다른 SQL 서버에서 데이터를 가져오고 싶습니다. 총 3 내 SQL 문은 모든 SQL Server에 동일합니다. 변경할 필요가있는 것은 연결 문자열과 데이터베이스뿐입니다. 여기 내 PHP 코드를 찾을 수 있습니다. 나는 PHP에서 $ _POST를 사용한다. 내 양식에서 액션을 받는다.
HTML에서 나는 select 옵션을 사용하고 있음을 볼 수 있습니다. 내가 'Grimbergen'을 선택할 때마다 연결 문자열이 $ connection_string = $ grim으로 변경되어야합니다. 나는 '신사'에 대한 선택 때 연결 문자열은
$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>
다른 데이터베이스에서 데이터를 가져오고 동일한 쿼리를 사용 하시겠습니까? – Gopalakrishnan
예. 쿼리는 동일합니다. –
괜찮아요. 젠체하는 젠장이 데이타베이스이거나 데이타베이스 이름을 말해 줍니까? – Gopalakrishnan