Php connection MSSQL problems

Source: Internet
Author: User
Php connection MSSQL problem my local wamp development environment is installed, because to develop a new site, however, the data is stored in the remote MSSQL Database. I found two methods to connect to MSSQL on the internet. One is that I cannot connect to mssql_connect & nbsp, then I connected 2 & lt ;? Php & nbsp; ** & nbsp; MSSQL connection in php
The development environment of wamp installed on my local machine, because I want to develop a new site, but the data is stored in the remote MSSQL database
I found two methods to connect to MSSQL on the internet. one method is that I cannot connect to mssql_connect. later, I connect to MSSQL using the method below.
2
/**

* Php uses ODBC to connect to an SQL server database instance
*/

$ Server = 'IP Address or server name ';
$ Username = 'database username ';
$ Password = 'database password ';
$ Database = 'database name ';

$ Connstr = "Driver = {SQL Server}; Server = $ server; Database = $ database ";

If (! Odbc_connect ($ connstr, $ username, $ password, SQL _CUR_USE_ODBC )){
Echo "Couldn't connect to SQL Server on $ server ";
} Else {
Echo "Connect successfully!
";
}
?>
Now the data connection is successful.
But how to write SQL query statements
If I write it like this later, an error will be reported.
If (! Odbc_connect ($ connstr, $ username, $ password, SQL _CUR_USE_ODBC ))
{Echo "Couldn't connect to SQL Server on $ server ";
}
Else {
While ($ row = mssql_fetch_array (mssql_query ('select * from t_item ')))
{

Echo $ row [0];

}
}

Warning: mssql_query () [function. mssql-query]: Unable to connect to server: (null) in C: \ wamp \ www \ mssql. php on line 12

Warning: mssql_query () [function. mssql-query]: A link to the server cocould not be established in C: \ wamp \ www \ mssql. php on line 12

Warning: mssql_fetch_array (): supplied argument is not a valid ms SQL-result resource in C: \ wamp \ www \ mssql. php on line 12


Isn't the query syntax of this connection written like this?

Php ms? SQL

Share:


------ Solution --------------------
$ Conn = odbc_connect ($ connstr, $ username, $ password, SQL _CUR_USE_ODBC );
$ Rs = odbc_exec ($ conn, 'select * from tbl_name ');

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.