2013-05-22 177 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