MSSQL连接使用PHP [英] MSSQL connection using PHP
本文介绍了MSSQL连接使用PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Iam这么新鲜的PHP,所以这个问题这么大对我来说。我不知道为什么,我的错误是在哪里。基于我的研究,使用此代码连接到MSSQL数据库:
Iam so fresh with PHP so this problem so big to me. I dont know why and where my mistake is. Based on my research to connect to MSSQL database by using this code:
<?php
$run = mssql_connect('dev-svr05','sa','P@55w0rd', 'orlig_sm_dev');
if ($run)
{
echo "Connection OK";
}
else
{
echo "Connection Failed";
}
?>
但是当我运行这个代码时,我得到了这个错误信息:
But when i run this code i got this error message:
PHP Fatal error: Call to undefined function mssql_connect() in C:\Inetpub\wwwroot\phpscript\save_mssql.php on line 5
我使用相同的代码连接到MYSQL及其成功,但不是与MSSQL。任何人都可以告诉我为什么会发生这种情况?谢谢
I using the same code to connect to MYSQL and its success but not with MSSQL. Can anybody please tell me why this is happen? Thank You
推荐答案
我会建议你从windows下载sql server二进制文件并使用PDO。
I would advice you download the sql server binaries from windows and use PDO.
try {
//In some occasions you only need to define IP/Hostname and you can forgo the \SQLEXPRESS part
$db = new PDO( "sqlsrv:Server=HOSTNAME\SQLEXPRESS;Database=DATABASENAME","USERNAME","PASSWORD");
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
// set this to your primary database
$db->query("USE DATABASENAME");
}
catch( PDOException $e ) {
die( "Error connecting to SQL Server".$e );
}
这篇关于MSSQL连接使用PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文