Want to connect PHP5 to MS SQL SERVER 2005 - php

I have an application that I made with PHP and MSSQL2000, but now want to connect it to a MSSQL2005 database. It's always failing and after doing some research I was told to download the ntwdblib.dll and replace the old one in my PHP directory which I did, but still cannot connect to it. I also uncommented the MSSQL extensions in my php.ini file.
Please can somebody help me with this?

http://www.php.net/manual/en/mssql.installation.php
The MSSQL extension is enabled by
adding extension=php_mssql.dll to
php.ini.
To get these functions to work, you have to compile PHP with
--with-mssql[=DIR] , where DIR is the FreeTDS install prefix. And FreeTDS
should be compiled using
--enable-msdblib .
also
MS SQL functions are aliases to Sybase functions if PHP is compiled with Sybase extension and without MS SQL extension.
<Edit>
Just asking. Do you have a mssql_connect function? Or does the connect fail? If the connection fails, be sure to enable TCP/IP in MSSQL (using SQL Server Configuration Manager). And I also recalled enabling Named Pipes, but I'm not sure it's needed.
</Edit>
As an alternative you could look at COM and ADODB.
Example of COM and ADODB, connecting to SQL Server using Windows Authentication:
$this->m_conn = new COM("ADODB.Connection");
$this->m_conn->CommandTimeout=1200;
$dsn="Provider=SQLNCLI;Data Source=server_name;Integrated Security=SSPI;Initial Catalog=database_name;Application Name=YourAppName - ".$user['name'];
$this->m_conn->Open($dsn);
if(!$this->m_conn)
throw new Exception("Could not start ADO",101);
$this->m_comm = new COM("ADODB.Command");
$this->m_comm->ActiveConnection=$this->m_conn;
$this->m_comm->CommandTimeout=1200;
Then execute a command
$this->m_comm->CommandText=$sql;
$res=$this->m_comm->Execute();
Then extract the data
if(($num_cols=$res->Fields->Count())>=1)
{
$return=array();
while(!$res->EOF)
{
$row=array();
for($i=0;$i<$num_cols;$i++)
$row[$res->Fields($i)->name]=$res->Fields($i)->value;
$res->MoveNext();
$return[]=$row;
}
}
$res->Close();
return $return;
Not sure about speed on a lot of requests, but it's a good way to do it without much fuss, and using DSNs with which you can specify much more than using function parameters.
EDIT:
You can define your own mssql_connect(), mssql_command(), etc, using ADO. That's a workaround if regular mssql extension won't work.

You can also try the build in database wrapper PDO from php.
Here is some information about PDO: PDO
And here is information on the use of MSSQL with PDO MSSQL and PDO

thank you very much for your help.
Actually i did find out a way of making it work
First of all let me start with what i have compared to the system requirements
MY SYSTEM
OS:-Win xP SP2
PHP :- 5.3.5
MSSQL 2005
SQL Native client 2005
Required
Recommended :-Win xP SP3
PHP :- 5.2.4 or later
MSSQL Server 2008 Native Client (on the same computer php is running)
SQL Server Driver For PHP
after upgrading my windows to service pack 3 i then downloaded and installed the MSSQL Server 2008 Native Client
then installed the SQL Server Driver For PHP 2.0 which ask for a directory to save the dll files.
I browse to the php directory and then the 'ext' folder where it copied the dll files to.
Then went to the php.ini file and add these two lines under the Dynamic Extensions.
extension=php_sqlsrv_53_ts_vc6.dll
extension=php_pdo_sqlsrv_53_ts_vc6.dll
Then restart my webserver and booommm....i got it working..
did a test connection to the database and it was succesfull..
Hope this will help others and thank you all for your assistance really appreciate it..
Peace

Related

Unable to connect to data source: library 'gds32.dll' failed to load - Firebird Connection PHP odbc_connect

I am trying to connect to a Firebird database using PHP.
This is the simple code that I use to connect to it.
$user = "******";
$password = "******";
$ODBCConnection = odbc_connect("DRIVER={Firebird/InterBase(r) driver};Database=******;Server=******;Port=******", $user, $password);
I have installed the ODBC driver for Firebird from this webpage https://www.firebirdsql.org/en/odbc-driver/. I've managed to add the correct (I believe) string to the DRIVER inside the ODBC Conection, but now I encounter this error:
Warning: odbc_connect(): SQL error: [ODBC Firebird Driver]Unable to connect to data source: library 'gds32.dll' failed to load, SQL state 08004 in SQLConnect
I am running an Apache server using XAMPP on localhost. Everything I wrote is in the index.php file, just trying to connect to the database.
Any help would be greatly appreciated.
This error occurs when you do not have the Firebird client library (fbclient.dll, or gds32.dll which is tried as a fallback) installed on your system (or you have it installed, but it has the wrong bitness).
To install the Firebird client library, use a Firebird server installer of the right bitness* (eg Firebird 3 Windows 64-bit from https://www.firebirdsql.org/en/firebird-3-0/), and install the Client components.
That said, if you're using PHP, it might make sense to use the Firebird PHP driver instead (though this will still need fbclient.dll to be installed).
*: right bitness: If you use a 32-bit PHP, you need the 32-bit client library, if 64-bit, then the 64-bit client library.

How to connect a cloud mssql db from xampp? [duplicate]

I have a xampp running with PHP 5.6. Normally I use mysql server, but for a script that already exists i need a MS SQL server.
I searched on the net and installed SQL server 2012.
But now I need the drivers for PHP. Unfornunately I can only find a version that supports 5.4, 5.5..
(http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx)
Is there a way to let this work with 5.6?
Microsoft recently released a new version (3.2) of the SQL Drivers for PHP which includes compatibility with PHP 5.6.
You can download the drivers here: https://www.microsoft.com/en-us/download/details.aspx?id=20098
I searched the net for a while.. After posting this question for 10m, I finally found a unofficial driver..
Hope this works, I will check this out..
You can find it on: http://robsphp.blogspot.be/2012/06/unofficial-microsoft-sql-server-driver.html
I believe it's time to revisit this answer a bit better.
Since you've been pretty clear with your setup. The short answer is placed as steps below
Download ver 3.2 of the SQLSRV drivers from here.
https://www.microsoft.com/download/details.aspx?id=20098
Do extract them to your "xampp installation path"\php\ext
Kindly ensure you see and keep the files : php_sqlsrv_56_ts.dll and php_pdo_sqlsrv_56_ts.dll
Please delete the redundant files below:
PHP Drivers License Terms.rtf,
php_pdo_sqlsrv_54_nts.dll,
php_pdo_sqlsrv_54_ts.dll,
php_pdo_sqlsrv_55_nts.dll,
php_pdo_sqlsrv_55_ts.dll,
php_pdo_sqlsrv_56_nts.dll,
php_sqlsrv_54_nts.dll,
php_sqlsrv_54_ts.dll,
php_sqlsrv_55_nts.dll,
php_sqlsrv_55_ts.dll,
php_sqlsrv_56_nts.dll,
release.txt,
SQLSRV_Readme.htm,
SQLSRV_ThirdPartyNotices.rtf,
Place these lines in your php.ini at your "xampp installation path"\php\php.ini
extension=php_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_ts.dll
Restart your XAMPP server and place a '<'?php phpinfo(); ?'>' in an index.php file at \htdocs\'folder'
Navigate to it using http://localhost/'folder where phpinfofile is placed'/index.php
If you see something like this image below. It's done, Congratulations]1
PS : The long answer is here.
https://msdn.microsoft.com/en-us/library/cc296170.aspx
At this time:
My solution was:
1- Download ver 3.2 of the SQLSRV drivers from here. https://www.microsoft.com/download/details.aspx?id=20098
2 Extract the files to your "xampp" folder into the \php\ext
3- Add this lines to php.ini
extension=php_pdo_sqlsrv_56_ts.dll
extension=php_pdo_sqlsrv_56_nts.dll
extension=php_sqlsrv_56_ts.dll
extension=php_sqlsrv_56_nts.dll

How to connect to Sybase via PHP

I'm trying to connect to a Sybase database with PHP5. I believe I've successfully compiled PHP with PDO_DBLIB, as phpinfo() lists dblib under PDO drivers, and freetds as the pdo_dblib flavour.
However, when I try to test a connection, I get an error reading:
'PDOException' with message 'could not find driver'
I'm trying to connect to a server on my LAN with this code:
$dbh = new PDO("sybase:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
Any suggestions would be greatly appreciated!
You should use dblib instead of sybase, like this:
$dbh = new PDO("dblib:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
PDO wouldn't work, or at least there is no PDO Sybase support for php. On Windows, you can use ODBC, and PDO_SQLSRV or PDO_ODBC, it might sound weird, but it should work.
Second option and I would recommend it, is to connect directly to Sybase (SqlAnywhere), but you need to install SQL Anywhere PHP Module
If you are using Ubuntu you can put the LD_LIBRARY_PATH inside envvars and it seems to read... still trying to find a way to get it to stick on RHEL based systems... Windows I am not too sure about I would hope you could set a system wide variable under
my computer -> properties -> advanced options
If are using RHEL based systems it might be better to include the:
export LD_LIBRARY_PATH=/path/to/library/ in the httpd restart script (check to see if it loads /etc/sysconfig/httpd and if so add the line in there - now restart apache and you should see some activity.

Making sql server 2008 connection with PHP with sqlsrv big problems

I know there are some threads with this topic, but I'm a little desperate now so I think I should do a new one. I´m trying to connect sql server 2008 with php, I'm using WAMP server and php 5.4.3. I have read a lot about the configuration of the php.ini file and I did what I needed to do. But still I can´t get my connection working!
This is a little summary of what I´ve done
Install the Microsoft® SQL Server® 2012 Native Client 64 bits in my case.
Download and move to php/ext folder the drivers SQLSRV30.EXE
Using your PHP folder, run command: "C:\PHP\php.exe" -i | more one I did that i got the next info: HP Extension Build => API(big number here) TS , VC9
with this information I found i need this new lines in my php.ini file
For SQLSRV30.EXE, PHP 5.4, TS, VC9 add lines:
[PHP_SQLSRV]
extension=php_sqlsrv_54_ts.dll
[PHP_PDO_SQLSRV]
extension=php_pdo_sqlsrv_54_ts.dll
Restart my server!!
Ok so I have a page whit this code:
<html>
<head>
<title>Resultado</title>
</head>
<body>
<?php
$server='ANDRES-PC';
$connectinfo=array("Database"=>"ejemplo");
//connect to DB
$db=sqlsrv_connect($server,$connectinfo);
if($db)
{
echo "Connection established.<br/>";
}
else
{
echo "Connection couldn't be established.<br/>";
die(print_r( sqlsrv_errors(), true));
}
?>
</body>
</html>
But when I try to see the page I got nothing!!! Not a single word. What do you thing is my problem. I used this page http://robsphp.blogspot.co.uk/2012/09/how-to-install-microsofts-sql-server.html to set up the connection!! please help
You've done everything correctly, so I'm guessing you have installed the 64 bit version of WAMP. Please see this answer:
http://social.msdn.microsoft.com/Forums/en-US/sqldriverforphp/thread/6dc1dc1a-5d74-415b-9225-ce11f481f301
Somewhere high up on my instructions page it says you must use 32 bit PHP:
"Microsoft's PHP driver for SQL Server only runs with PHP 32-bit builds"
Edit: never mind! I noticed your recent comment on my blog page: http://robsphp.blogspot.co.uk/2012/09/how-to-install-microsofts-sql-server.html
I'll leave this answer as it's a common reason for the sqlsrv driver not loading with WAMP.
Sqlsrv driver works only with 32-bit version of wamp. Install 32-bit version of wamp or connect to MSSQL using PDO connection with odbc driver
new PDO("odbc:dsn");

How to set up OCI to connect to Oracle from PHP?

On the latest Ubuntu, I have a functioning PHP 5.2.4 installation. I want to use a remote Oracle server from PHP using OCI.
I've downloaded the "Instant Client Package - Basic Lite" (Link). I've unzipped the package containing the OCI libraries to a dir but I have no idea how to tell PHP that I want to use these libraries. Predictably, I get
Fatal error: Call to undefined function oci_connect() in...
when running this code:
<?php
$conn = oci_connect('hr', 'hrpw', 'someremotehost');
?>
I don't want to recompile PHP with Oracle support. What's the fastest way to wire up PHP so that I can use Oracle? Do I need any other libaries, like the Oracle client if I want to connect to a remote Oracle instance?
You need the PHP extension, try the following on your Ubuntu:
(sudo) pecl install oci8
Make sure your php.ini's (there should be one for your Apache and one for cli php) contain extension=oci8.so afterwards. Finally, you have to restart Apache and can confirm via <?php phpinfo(); ?> that the extension is loaded.
UPDATE:
Enter something like this when it asks you for ORACLE_HOME:
instantclient,/opt/oracle/instantclient
I think setting the environment variable would be another solution. /opt/oracle... is the path I put my instantclient in. I followed some tutorial a while ago, unfortunately I can't find it anmore.
HTH
I think you'll need to make sure that the $ORACLE_HOME/lib32 is in your $LD_LIBRARY_PATH, or else add that directory to the /etc/ld.so.conf file.
In the end, I downloaded Zend Core for Oracle and that worked.
http://www.zend.com/en/products/core/for-oracle

Categories