I'm trying to connect to a Windows MS Sql Server database using PHPon Linux and I know I have the hostname, port, userid and password correct. I verified this with some client software to make sure I could get to the database. So I'm sure it's just either the right driver, method, or a syntax issue. Maybe how the port is used in these.:
This is just example names etc.
$server = "myhost.com:1111";
$database = "mydatabasename";
$user = "johndoe";
$pass = "doe1";
$conn = odbc_connect('myhost.com','1111','johndoe','doe1');
or
$connection_string = "DRIVER={SQL Server Native Client 10.0};SERVER=$server, 1433;DATABASE=$database";
$conn = odbc_connect( $connection_string, $user, $pass );
i did a variation on this using just "SQL Server" as the driver after I found a post about using that instead.
I also tried this:
mysql_connect($server,$user, $pass) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($database);
$query = "SELECT * FROM USER_TABLE ";
Here some information on the server and database: Windows Server Standard 2007 MS SQL Server 2008 Standard Edition Using SQL Server Authentication
I'd prefer the odbc_connect if possible. We use it to connect to another database on an i-Series and that works fine. But we didn't have to use port either on those.
Thanks Michael
Here is an up-to-date doc on setting up SQL Server/Drivers on Ubuntu for PHP development.
https://www.microsoft.com/en-us/sql-server/developer-get-started/php/ubuntu/
sudo apt-get install unixodbc unixodbc-dev ( I already had this so didn't need to do this one.)
sudo apt-get install tdsodbc freetds freetds-bin php5-odbc
The rest is pretty much here: http://help.interfaceware.com/kb/904
On my virtual machine of course my driver was located at /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
my obdbcinst.ini
[FreeTDS]
Description = FreeTDS drvier
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i836-linux-gnu/odbc/libtdsS.so
FileUsage = 1
Usagecount = 1
[AS400]
Driver = /usr/lib/libcwbodbc.so
System = mydatabaseserver.com
Setup =
FileUsage = 1
Usagecount = 1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.