<?php
//链接数据库
$conn=mssql_connect("localhost","xmxgzcrm","xmxgzcrm123");
mssql_select_db("xmxgzrccrm",$conn);
//query语句
$Query="select top 10 * from employee";
$AdminResult=mssql_query($Query);
//输出结果
$Num=mssql_num_rows($AdminResult);
for($i=0;$i<$Num;$i++)
{
$Row=mssql_fetch_array($AdminResult);
echo($Row[1]);
echo("<br/>");
}
?>运行结果:
Warning: mssql_connect() [function.mssql-connect]: message: 用户 'XGZ-20101226128\IUSR_XGZ-20101226128' 登录失败。 (severity 14) in D:\liu\index.php on line 3Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost in D:\liu\index.php on line 3Warning: mssql_select_db(): supplied argument is not a valid MS SQL-Link resource in D:\liu\index.php on line 4Warning: mssql_query() [function.mssql-query]: message: 用户 'XGZ-20101226128\IUSR_XGZ-20101226128' 登录失败。 (severity 14) in D:\liu\index.php on line 7Warning: mssql_query() [function.mssql-query]: Unable to connect to server: (null) in D:\liu\index.php on line 7Warning: mssql_query() [function.mssql-query]: A link to the server could not be established in D:\liu\index.php on line 7Warning: mssql_num_rows(): supplied argument is not a valid MS SQL-result resource in D:\liu\index.php on line 9
//链接数据库
$conn=mssql_connect("localhost","xmxgzcrm","xmxgzcrm123");
mssql_select_db("xmxgzrccrm",$conn);
//query语句
$Query="select top 10 * from employee";
$AdminResult=mssql_query($Query);
//输出结果
$Num=mssql_num_rows($AdminResult);
for($i=0;$i<$Num;$i++)
{
$Row=mssql_fetch_array($AdminResult);
echo($Row[1]);
echo("<br/>");
}
?>运行结果:
Warning: mssql_connect() [function.mssql-connect]: message: 用户 'XGZ-20101226128\IUSR_XGZ-20101226128' 登录失败。 (severity 14) in D:\liu\index.php on line 3Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost in D:\liu\index.php on line 3Warning: mssql_select_db(): supplied argument is not a valid MS SQL-Link resource in D:\liu\index.php on line 4Warning: mssql_query() [function.mssql-query]: message: 用户 'XGZ-20101226128\IUSR_XGZ-20101226128' 登录失败。 (severity 14) in D:\liu\index.php on line 7Warning: mssql_query() [function.mssql-query]: Unable to connect to server: (null) in D:\liu\index.php on line 7Warning: mssql_query() [function.mssql-query]: A link to the server could not be established in D:\liu\index.php on line 7Warning: mssql_num_rows(): supplied argument is not a valid MS SQL-result resource in D:\liu\index.php on line 9
sql server 是选择sqlserver/windows验证模式 账号密码是sqlserver下建的 不是windows登录账号按照以下方法配置了php,a、打开php.in将extension=php_mssql.dll的注释符号去掉。 b、打开php.in将mssql.secure_connection = Off改为on。 c、将php_mssql.dll拷贝到php.in中extension_dir 指定的目录或者系统system32目录下。(php_mssql.dll在php的压缩安装包中有)。php版本是PHP Version 5.2.17
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$server = 'KALLESPC\SQLEXPRESS';// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi');if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
?>