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 ');