我想用php连接到sql server。我有一个用户表,但我无法连接服务器。
登录.php
<html>
<form action='LoginAction.php' method='POST'>
Username: <input type='text' name='username'/><br/>
Password: <input type='password' name='password'/><br/>
<input type='submit' value='Login'/>
</form>
</html>
我尝试了 2 个代码到 LoginAction.php
首先:
<?php
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$connect = mysql_connect("myphpadmin.net", $username, $password, "my_db") or die("Couldn't connect!");
mysql_select_db("users") or die("Coulnd't find db!");
}
else
{
die("please fill in all fields.");
}
?>
第二:
<?php
$connection=mysqli_connect("example.com",$username, $password,"my_db");
// Check connection
if (mysqli_connect_errno($connection))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_close($connection);
?>
另外,我创建了一个表“users.sql”并尝试将其放入我的代码中,但它仍然无法正常工作。你能帮助我吗?
感谢帮助者!
编辑:我想我会像aldanux所说的那样尝试用PDO来做,谢谢大家!