Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQL server php登录脚本_Php_Sql Server - Fatal编程技术网

SQL server php登录脚本

SQL server php登录脚本,php,sql-server,Php,Sql Server,我已经创建了脚本来验证我的登录系统,但是我很难弄清楚如何让它专门登录到我的sqlserver帐户到我的特定工作空间我的登录脚本如下所示 <?php session_start(); if(!isset($_SESSION["user_id"])){ header("location:../../login.html"); } $username = $_POST['txt_username']; $user_id = $_POST

我已经创建了脚本来验证我的登录系统,但是我很难弄清楚如何让它专门登录到我的
sqlserver
帐户到我的特定工作空间我的登录脚本如下所示

<?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");

?>

阅读:

下面是连接到MSSQL服务器数据库的代码
//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);
?>
//与数据库的连接
//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);
?>
$dbhandle=mssql\u connect($myServer、$myUser、$myPass) 或者死亡(“无法连接到$myServer上的SQL 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);
?>
$selected=mssql\u select\u db($myDB,$dbhandle) 或者死亡(“无法打开数据库$myDB”);
//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);
?>
//声明将查询数据库的SQL语句
//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);
?>
$query=“选择id、名称、年份”; $query.=“来自汽车”; $query.=“WHERE name='BMW'”; //执行SQL查询并返回记录 $result=mssql_查询($query); $numRows=mssql\u num\u行($result); “回声”$努姆罗斯。“行”。($numRows==1?“:“s”)。“返回”; //显示结果 while($row=mssql\u fetch\u数组($result)) { 回声“
  • ”$row[“id”]。$row[“name”]。$row[“year”]。“
  • ”; } //关闭连接 mssql_关闭($dbhandle); ?>
    使用DSN连接

    DSN代表“数据源名称”。这是一种为数据源分配有用且易于记忆的名称的简单方法,数据源可能不仅仅限于数据库

    //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);
    ?>
    
    在下面的示例中,我们将向您展示如何使用DSN连接到名为“examples”的MSSQL服务器数据库,并从表“cars”中检索所有记录

    //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);
    ?>
    
    <?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"; 
    ?>
    
    
    
    这实际上并没有连接到数据库以允许我获取登录详细信息。这里是检查用户名和密码的查询?请告诉我您使用的是Microsoft SQL server还是Mysql数据库。如果您使用的是SQL server。按照下面的编码//创建指向MSSQL$link=MSSQL_connect('KALLESPC\SQLEXPRESS','root','pass')的链接;//选择数据库“php”mssql\u Select\u db('database1',$link);SQL 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);
    ?>