Does anyone know how I can install an Ms SQL extension 2005 on a Linux webserver? The webserver currently has FreeTDS library version, I have no idea on what that means. But when I try to connect it doesn't say
mssql_connect() does not exist
But it says
Unable to connect to server: xx.xx.xx.xx
I am supposing that this is because of the version of the extension since I have occured this problem on windows with ntwdblib.dll. But I don't know how to fix this on Linux.
I only need to use the functions. The database is on a windows server so I want to connect to it using mssql_connect().
The webserver is not my own it's a hosting company where I happen to know the hoster so I cannot ask him if he could install windows instead or anything. So could someone tell me how it could work for linux?
I tested it with my own pc and I can connect to the windows server from my pc. But from the webserver it doesnt, it says:
unable to connect to the server: "ip"
There are 2 parts to this:
FreeTDS... you will need to edit /etc/freetds.conf to include definition of the connection.
[CON1]
host = xxx.xxx.xxx.xxx
port = 1433
tds version = 8.0
client charset = UTF8
text size = 20971520
[CON2]
host = xxx.xxx.xxx.xxx\PIPENAME
port = 1433
tds version = 8.0
client charset = UTF8
text size = 20971520
Then, I would ignore the mssql_commands directly, and use PHP ADODB ( http://adodb.sourceforge.net/ ) to connect and run queries (especially if yoi intend to execute Stored Procs - PDO works too, but ADODB works and is reliable and consistent with SQL Server). To connect to sql server using it once you have aquired it etc:
$dbMS1=ADONewConnection("mssql");
$dbMS1->Connect('CON1','brs','TFaqAIs8');
$dbMS1->SelectDB('TheDatabase');
$sql = "SELECT .......";
$rs = $dbMS1->Execute($sql);
Related
I try to run an ibase_connect to an firebird database.
The database is NOT on my localhost. It run on an network windows server.
I have windows too and have an connection to the shared folder:
Z:\Folder_WITH_DB.
I have XAMPP installed with
ibase extension
pdo firebird extension.
I copied the fbclient.dll into my XAMPP/php folder.
But if i run this code:
$db = 'Z:/Folder_WITH_DB/database.fdb';
$username='SYSDBA';
$password='masterkey';
$dbh = ibase_connect ( $db, $username, $password ) or die ("error in db connect");
gives this error
Warning: ibase_connect(): Unable to complete network request to host "Z". Failed to locate host machine. in xxx/index.php on line xx
firebird.log:
INET/INET_connect: gethostbyname (Z) failed, error code = 11004
I added gds_db 3050/tcp to the service file on my localhost and the server (have restarted both) and it is the same error.
Windows Firewall is deactivated on server. Service for firebird server and firebird guardian is running.
Firebird can only use a database file local to the database server. You can't connect to a Firebird database on a network share*. You need to connect to the Firebird server instead.
So if the database of 'Z:/Folder_WITH_DB/database.fdb' is on server firebirdsrv in folder D:\data\database.fdb, then you need to connect to firebirdsrv/3050:D:\data\database.fdb. I strongly suggest to remove the networkshare.
*: Technically a share can be used, but it is disabled by default because accessing a database from multiple servers through a network share can corrupt a database.
I am trying to find out whether it is possible or not to connect to a remote Sybase server using the Sybase PHP extension and the function sybase_connect().
Actually, I cannot find any explicit answer to this question on the internet. I tried using the function like this:
$con = sybase_connect('ip:port','sa','password');
but I keep getting the error:
Warning: sybase_connect(): Sybase: Unable to connect in ...*
The server is reachable using a Sybase client such as Toad for Sybase for instance.
I am working with Windows 7 64bit and Wamp.
Would you please have any more details?
If you're using FreeTDS, I believe you need to add some settings to your freetds.conf file (mine is in /usr/local/etc/):
[ServerName]
host = 1.2.3.4
port = 1433
tds version = 8.0
"ServerName" can be anything you'd like. You should then be able to connect to it using sybase_connect('ServerName','sa','password')
I'm trying to browse a customer's Microsoft SQL server database with PHP but port 1433 is closed. Digging around I found out MSSQL can run in Dynamic Port Allocation mode, that means it will choose a random listen port at first execution, and will likely remain the same accross startup. I know I can find out the current port, but since likely is not always and I'd like to avoid searching for it again, is there any way to remotely discover the port to connect to?
From what I could understand by my searches this job is usually accomplished by SQLBrowser(.exe ?), but how to do this on Linux?
Update on the solution
While #Chris' answer was correct I was missing a simple but essential bit: on every change of odbc.ini you need to run:
odbcinst -i -s -f /etc/odbc.ini
to update system's DSN.
After that I could connect using
isql -v DSN_NAME username password
Troubleshooting
To check server instance:
tsql -H HOSTNAME_OR_IP -L
this will print server information, including instance names and port to which you should be able to connect using standard telnet or mssql client.
Given that your answer was correct, I had to do minor changes to make it work. I decided to write them here. Steps are basically the same. On Ubuntu/Debian:
apt-get install php5-sybase unixodbc tdsodbc
Edit /etc/odbcinst.ini and add driver details
[TDS]
Description = FreeTDS Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
Edit /etc/odbc.ini and enter connection details
[SQLSRV01]
Description = SQL Server test
Driver = TDS
Trace = No
Server = SERVER_IP\INSTANCE_NAME
TDS_Version = 9.0
#Database = DataBaseName
#ReadOnly = Yes
The last two parameters are optional. Driver must match what we wrote in odbcinst.ini. The Server directive must be in that syntax (of course SERVER_IP can be an hostname too).
According to UnixODBC the next step should not be necessary, but this is what made my installation work. Run the following command (every time odbc.ini is changed)
odbcinst -i -s -f /etc/odbc.ini
After this you should be able to connect using:
isql -v SQLSRV01 nome_utente password
Or via PHP:
$db = new PDO("dblib:host=SQLSRV01;dbname=DBNAME","USERNAME","PASSWORD");
Short answer:
ODBC drivers know to contact SQL server on port 1434 to find which dynamic port is associated with a named instance. user SERVERNAME\INSTANCENAME to connect.
Long answer:
I started here which led here and here.
Eventually I found this:
If you are using mssql with multiple instances and dynamic port
allocation you can use the following:
[SQLServer2008]
Description = Production Server
Driver = TDS
Trace = No
Server = servername\instance_name
TDS_Version = 8.0
Which seems to be echoed in a similar IBM Doc:
Question
SQLServer is setup to dynamically assign ports. In the .odbc.ini file,
the Address parameter is usually set to hostname colon port number
(Address=HostName:1433), but the port may change. How should we handle
this?
Answer
For the Address parameter value, instead of entering the hostname
colon port, enter the hostname a backslash and the server instance
name.
For example, in Unix/Linux, use the IBM SQLServer Wire Protocol driver
and enter the following in the .odbc.ini file in the DSN definition
for the connection to the SQLServer data source:
Address=HostName\Server_Instance_Name
For Windows, use the ODBC Data Sources Administrator to configure a
System DSN for the data source using the IBM SQLServer Wire Protocol
driver.
Note: The parameter is Server
I encountered a problem that I have spent hours fixing that. Here is the problem:
I am trying to connect to a remote Oracle 8i server using Oracle 11 instant client: here is my connection string in PHP:
$conn = oci_connect('db_user', 'db_pass', "db_ip/db_service");
db_ip is the ip of the server, such as "12.34.56.78".
db_service is the service of server, such as "test".
The error shown is
ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
I could use the same client to connect to another Oracle 10g server. The php code is same, only change the db_user or db_pass or db_ip. db_service is not provided.
I don't use tnsnames.ora for either oracle 10g server or oracle 8i server. I just use the simple IP of server. Does this matter?
Server using: Windows Server 2008 R2
PHP: php 5.2.17
Oracle Instant Client: 11_2
Any ideas will be appreciated.
Updated
Php can also work now. My php folder is under Programfiles (x86), the parenthesis is not allowed. So I moved the whole folder to C:\php, and configure the IIS to change php version. Reference:http://stackoverflow.com/questions/9215983/php-cant-connect-but-sqlplus-can
Updated
Thanks so much for Justin's help. It works!!! I just changed the sid to scblive instead of SCBLIVE. Their database name is scblive. I am still using 10.2.0.1, using sqlplus, I can connect to both oracle 10g and oracle 8i. Thanks soooo much!!
This is the tns names that works for oracle 8i:
scblive =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = [oracle 8i ip])(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = scblive)
)
)
Another problem found, in php code, it shows the same error for either oracle 10g or oracle 8i.
ORA-12154: TNS:could not resolve the connect identifier specified
I just used following connection string:
$conn = oci_connect('user_name', 'pass', 'scblive');
for oracle 10g, if I used same connection string as before, the error still shows:
$conn = oci_connect('user_name', 'pass', [oracle 10g ip]);
Any ideas?
Earilier Update:
Thanks for #Justin's help. have tried 10.2.0.5, 10.2.0.4 or 10.1.0.0, none of them could work. I saw the the matrix. it seems instant client 8.1.7 or instant client 9.0.1 could work for both oracle 10g and oracle 8i. Does anyone have a link for those files? Oracle could only provide 10.1.0.5 and later.
This is expected behavior. The 11.2 client is not certified to connect with any version of Oracle 8i. You would need to have at least an Oracle 9.2.0.4 database. If you want to connect with and 8.1.7 database, you would need an Oracle 10.2 or earlier client. The initial versions of the 10.2 client were not compatible with a Windows Server 2008 R2 system but it should be possible to install the 10.2.0.5 client patchset. If you want to connect to an Oracle database that is earlier than 8.1.7, you would need an earlier version of the Oracle client which would probably require installing an earlier version of Windows.
If you have Metalink access, Metalink 207303.1 is the Client/ Server Interoperability Matrix.
If you really have the 10.2.0.5 full client installed, your TNS alias needs to use a SID. Service names didn't exist back in 8.1.7. You probably want to copy a TNS alias from a machine that is able to connect to the 8.1.7 database. My guess is that you want
SCBLIVE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = [ORACLE 8i IP])(PORT = 1521))
(CONNECT_DATA = (SERVER = DEDICATED)(SID = SCBLIVE))
)
If that doesn't work, at a command line, type tnsping scblive and copy and paste the results.
I copy my previous Oracle 9/8 client's ora.... folder and all relevant dll to a specific folder and put these two folders into path variable. At a time, I succeed to connecting with Oracle 8.1.7 using oci in php.
We are using MSSQL server 2008 on Win server 2008 R2 and have installed Apache (2.2.19) and PHP (5.2.17) separately. We have installd the MSSQL module for PHP and usingthe following connection string:
$myc = mssql_connect(Server, SiteDatabaseUsername, SiteDatabasePassword) or die('Can\'t connect to mssql Database Server: '.mssql_get_last_message($myc));
$db = mssql_select_db(SiteDatabaseName, $myc) or die('Can\'t find database: '.mssql_get_last_message($myc));
But it gives us this error:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: localhost\MSSQLSERVER in D:\Apache2.2\htdocs\adminarea\_core.php on line 89
Can't connect to mssql Database Server:
We have used the IP:PORT, localhost\MSSQLSERVER and COMPUTERNAME\MSSQLSERVER but don't seem to be getting anywhere, can anyone help please?
A few things come to mind:
1) Make sure you have the sqlsrv driver package from MS, and make sure you're loading it properly in php.ini (use phpinfo() to verify).
2) If this was a vanilla installation of SQL Server, its likely that only windows authentication is turned on. Open the SQL Enterprise Manager and make sure you have SQL Server Authentication enabled on your database.
3) Make sure that you have enabled network access to SQL Server. I'm not immediately certain whether the new MS drivers use named pipes to communicate with the server, or if they expect that the server will be accessed via the network.
These are the issues I routinely encounter when getting PHP speaking to a new MSSQL server.