Am creating an ionic application using php, at the beginning I've linked the login form with a mysql database that I've created using wamp as a server and everything works fine! then my boss saids that I have to change it to another database which is on a Microsoft sql server, so I've linked the wamp server with MsSQL and the Connection with database on MSSQl established correctly
but I didn't know how to change the syntaxe on login.php
Here are the old and new cofig.php that works fine
(New config.php)
<?php
$serverName = "HAMDI-PC";
$connectionInfo = array ("Database"=>"MAINT","UID"=>"sa","PWD"=>"sql") ;
$conn = sqlsrv_connect( $serverName, $connectionInfo);
?>
(OLD config.php)
<?php
$conn = new mysqli("localhost", "root", "", "MAINT");
?>
And here is the (login.php) that works with mysql database
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
if(isset($_GET["username"]) && isset($_GET["password"]) ) {
if( !empty($_GET["username"]) && !($_GET["password"]) ) {
include"config.php";
$username=$_GET["username"];
$password=$_GET["password"];
$query=" SELECT * FROM D_PROTUSERS WHERE PROT_User='$username' AND PROT_Password ='$password' ";
$result = $conn->query($query);
$out="";
if ($rs=$result->fetch_array()) {
if($out != "") {$out .="";}
$out .='{"PROT_User":"'. $rs["PROT_User"] . '",';
$out .='"PROT_Password":"'. $rs["PROT_Password"] . '"}';
}
$out='{"recods":'.$out.'}';
$conn->close();
echo($out);
}
}
?>
So please I want to know what should I change to make it work at the new database'MSSQl) , I'll be thankful to everyone who will tries to help :*
Forget about mysql, you're using ms sql.. so you have to use sqlsrv
Here we go.
config.php
$serverName = "HAMDI-PC\SQLEXPRESS";
$dbname = "MAINT";
$uid = "sa";
$pwd = "sql";
global $con;
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>$dbname);
/* Connect using SQL Server Authentication. */
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
die( print_r( sqlsrv_errors(), true));
}
And
login.php
<?php
session_start();
include"config.php";
$username=$_REQUEST["username"];
$password=$_REQUEST["password"];
$query = " SELECT * FROM D_PROTUSERS WHERE PROT_User='$username' AND PROT_Password ='$password' ";
$result = sqlsrv_query($conn, $query, array() , array(
"Scrollable" => 'keyset'
));
$num = sqlsrv_num_rows($result);
if ($num > 0)
{
$_SESSION["valid_user"] = true;
$_SESSION['username'] = $username;
sqlsrv_close($conn);
}
else
{
echo "Login Failed: Connection could not be established.";
exit();
}
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.