How to connect PHP to the SqlServer database I just started to contact PHP to connect to the database .. Almost all the tutorials are MySql. how can I connect to the SQL Server database. I have configured all the configuration methods found on the Internet. But there is no ntwdblib. dll file under my installation directory.
The code is as follows:
$ Conn = @ mssql_connect ("localhost", "zhengjie", "123") or die ("connection error! ");
Mssql_select_db ("student information management ");
If ($ conn)
{
Echo "connection successful! ";
}
?>
No prompts after running ...... Please help ...... Thank you.
Reply to discussion (solution)
Remove @ before mssql_connect and check the error feedback.
It is more convenient to use ODBC.
Good question, no
When @ is used, it is a warning, not an error ......
What is a warning?
The code cannot be seen, but the configuration is incorrect. have you done the following steps?
1. open the PHP configuration file php. ini and find; extension = php_mssql.dll and remove the semicolon.
2. find mssql. secure_connection = Off and change it to mssql. secure_connection = On.
3. copy the php_mssql.dll and ntwdblib. DLL files in the PHP folder to the C: \ windows \ system32 \ folder.
4. restart Apache. OK.
You do not need to use odbc to directly use php. activate php_mssql.dll in php. ini. It is disabled by default.
Pdo is now popular.
How to use PDO... I have done all the work on the fifth floor. However, my PHP does not contain ntwdblib. DLL. Is it a PHP error ......
Your php version?
1. First, make sure that you can log on to the SQL _server server with "zhengjie" and "123" (SQL authentication is included)
2. we recommend that you directly download the Wamp version (you may have problems configuring the environment yourself). you can directly enable the PHP_MSSQL module.
At least I will never be able to connect with this one.
3. try to connect with COM
How to use COM to connect
To allow DCOM, remove the semicolon ";" before; com. allow_dcom = TRUE in php. ini.
$conn = new COM("ADODB.Connection") or die("Cannot start ADO"); $connstr = "Provider=SQLOLEDB; Persist Security Info=False; User ID=sa; Password=; Initial Catalog=cdr; Data Source=localhost"; $conn->Open($connstr);
I use wamp, PHP version 5.3.3, and the module is enabled .. However, if the connection fails, there will be no prompts at all. he will not prompt you to connect, nor will he prompt an error message .. If you have a master, leave a QQ account and add me to help me ...... 602788658. thank you ......
$ Conn = @ mssql_connect ("localhost \ MS2005", "zhengjie", "123") or die ("connection error! ");
Mssql_select_db ("student information management ");
If ($ conn)
{
Echo "connection successful! ";
}
Else
{
Echo "connection error! ";
}
?>
$ Conn = @ mssql_connect ("localhost \ MS2005", "zhengjie", "123") or die ("connection error! ");
If ($ conn)
{
Echo "connection successful! ";
}
Else
{
Echo "connection error! ";
}
Echo "";
?>
In this case, A does not output any output. Is there any error in my code ......
It should be when mssql_connect () is executed and the program fails to be aborted unexpectedly.
Remove @ to make it report an error.
It should be when mssql_connect () is executed and the program fails to be aborted unexpectedly.
Remove @ to make it report an error.
Fatal error: Call to undefined function mssql_connect () in E: \ PHP \ mysql \ MySql1.php on line 2
Http://blog.xmnn.cn /? Uid-525196-action-viewspace-itemid-906722
Download ntwdblib. dll
What is your SQL SERVER version? For versions later than 2005, you must install the official driver.
Http://msdn.microsoft.com/zh-cn/library/cc296152%28v= SQL .90%29.aspx
You use
Mysql_error ()
Check the error message.
I have never known how to continue after a long time .....