我正在尝试使用PHP在我的MSSQL表中插入用户名和密码。我不熟悉MSSQL,但它适用于客户端。当我尝试在网站上运行我的PHP页面时,我收到错误mssql_query(): supplied argument is not a valid MS SQL-Link resource in
。
这是我的PHP页面代码:
<?php
$con=mssql_connect("gbs.com","Gser","Robs1!","GBMser");
var_dump($con);
// Check connection
if (!$con) {('Something went wrong while connecting to MSSQL'); }
if ($con) {
echo ("Connection is succeed");
} else {
echo ("Connection is fail");
}
var_dump($con);
mssql_query($con,"INSERT INTO users (username, password)
VALUES ('d', md5('d'))");
if (!mssql_query) {
// The query has failed, print a nice error message
// using mssql_get_last_message()
die('MSSQL error: ' . mssql_get_last_message());
}
mssql_close($con);
?>
以下是我运行代码时显示的PHP页面:
resource(1) of type (mssql link) Connection is succeedresource(1) of type (mssql link)
Warning: mssql_query(): supplied argument is not a valid MS SQL-Link resource in D:\Hosting\4502990\html\insertadminaccount.php on line 14
感谢任何帮助。谢谢大家。
答案 0 :(得分:1)
使用代码使其工作:
<?php
$Conn=mssql_connect('servername','username','password!');
mssql_select_db('dbname',$Conn);
if( mssql_select_db ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
?>
答案 1 :(得分:0)
你必须像这样写
mssql_query("INSERT INTO users (username, password)VALUES ('rob_dewar01', md5('KingDozer'))",$con);
首先查询然后连接,希望它有帮助