2013-05-22 202 views
0

我已經創建了腳本來驗證我的登錄系統,但我無法弄清楚如何使它專門登錄到我的具體工作空間我的sqlserver帳戶我登錄腳本到目前爲止以下SQL服務器php登錄腳本

<?php 
    session_start(); 

    if(!isset($_SESSION["user_id"])){ 
     header("location:../../login.html"); 
    } 

    $username = $_POST['txt_username']; 
    $user_id = $_POST['txt_password']; 


    mysql_connect($server, $username, $password) or die("No Server Found"); 

    mysql_select_db($schema) or die("No Connection"); 

?> 
+0

什麼是錯誤? –

+0

有什麼問題? – Robert

+0

這實際上並未連接到數據庫以允許我提取登錄詳細信息 – Tasty

回答

0

閱讀:http://php.net/manual/en/function.mssql-connect.php

下面是用於連接到MSSQL Server數據庫

//connection to the database 
$dbhandle = mssql_connect($myServer, $myUser, $myPass) 
    or die("Couldn't connect to SQL Server on $myServer"); 

//select a database to work with 
$selected = mssql_select_db($myDB, $dbhandle) 
    or die("Couldn't open database $myDB"); 

//declare the SQL statement that will query the database 
$query = "SELECT id, name, year "; 
$query .= "FROM cars "; 
$query .= "WHERE name='BMW'"; 

//execute the SQL query and return records 
$result = mssql_query($query); 

$numRows = mssql_num_rows($result); 
echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>"; 

//display the results 
while($row = mssql_fetch_array($result)) 
{ 
    echo "<li>" . $row["id"] . $row["name"] . $row["year"] . "</li>"; 
} 
//close the connection 
mssql_close($dbhandle); 
?> 
代碼0 將帶有DSN

ODBC Functions

DSN代表 '數據源名稱'。這是一種簡單的方法,可以將有用且易於記憶的名稱分配給數據源,這些數據源可能不僅限於數據庫。

在下面的例子中,我們將向您展示如何將DSN連接到名爲'examples'的MSSQL Server數據庫,並從表'cars'中檢索所有記錄。

<?php 

//connect to a DSN "myDSN" 
$conn = odbc_connect('myDSN','',''); 

if ($conn) 
{ 
    //the SQL statement that will query the database 
    $query = "select * from cars"; 
    //perform the query 
    $result=odbc_exec($conn, $query); 

    echo "<table border=\"1\"><tr>"; 

    //print field name 
    $colName = odbc_num_fields($result); 
    for ($j=1; $j<= $colName; $j++) 
    { 
    echo "<th>"; 
    echo odbc_field_name ($result, $j); 
    echo "</th>"; 
    } 

    //fetch tha data from the database 
    while(odbc_fetch_row($result)) 
    { 
    echo "<tr>"; 
    for($i=1;$i<=odbc_num_fields($result);$i++) 
    { 
     echo "<td>"; 
     echo odbc_result($result,$i); 
     echo "</td>"; 
    } 
    echo "</tr>"; 
    } 

    echo "</td> </tr>"; 
    echo "</table >"; 

    //close the connection 
    odbc_close ($conn); 
} 
else echo "odbc not connected"; 
?> 
+0

謝謝這是一個很大的幫助。 – Tasty