Making sql server 2008 connection with PHP with sqlsrv big problems - php

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

Related

Installing on XAMPP PHP7.4.11 SQLSRV drivers [duplicate]

I trying to connect to an SQL Server in PHP. With XAMPP on my local machine, everything works well. But now I going to bring my application on the production server.
On this server there is installed the Microsoft IIS 6.1 and running the PHP version 7.0.7. I also installed the ODBC Driver from here. Next I decomment the following line in my php.ini file:
extension=php_sqlsrv_7_nts.dll
extension=php_pdo_sqlsrv_7_nts.dll
I got the files from the official microsoft site.
What's my problem?
Unfortunately, after I restarted the IIS. The PDO function throws the PDOException error with the following message:
could not find driver
For the connection I am using the following function which works pretty well on my local machine:
try {
$con = new PDO("sqlsrv:Server=" . SERVER . ";Database=" . DATABASE, USERNAME, PASSWORD);
// set the PDO error mode to exception
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "No connection: " . $e->getMessage();
exit;
}
What can I else do?
Here is detailed process if it's helpful for someone. PHP Version - 7.4
Download and extract the .dll files from this link - https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15
Paste the files in C:\xampp\php\ext, your path could be different.
in php.ini add those two lines at bottom or in extension section.
extension=php_sqlsrv_74_ts_x64.dll
extension=php_pdo_sqlsrv_74_ts_x64.dll
Restart your Xampp server, I'll suggest restart your computer and everything will work without an issue then.
Check if SqlSRV enabled
Check using phpinfo() or http://localhost/dashboard/phpinfo.php at like this -
Hope, it will help someone.
After I found the error log on the Windows Server, I solved the error by myself.
I got this error in my log:
[21-Apr-2017 07:12:14 UTC] PHP Warning: PHP Startup: Unable to load dynamic library '...\ext\php_pdo_sqlsrv_7_nts.dll' - %1 is not a valid Win32 application. in Unknown on line 0
Then I downloaded again the driver and installed the x64-Driver. Finally It works without any problems.
please notice you must use the correct version of php_sqlsrv_xx_xts_xxx.dll and php_pdo_sqlsrv_xx_xts_xx.dll files.
for exmple if you use php version 7.4 and a 64 bit system and wamp you must download and use these files:
php_sqlsrv_74_ts_x64.dll
php_pdo_sqlsrv_74_ts_x64.dll
for download you can use this site:
https://go.microsoft.com/fwlink/?linkid=2152937
https://learn.microsoft.com/en-us/sql/connect/php/download-drivers-php-sql-server?view=sql-server-ver15
It took some time for me to solve the 'No driver'-error. I went through some steps as mentioned here and found some other ones that helped me after new errors. For future references:
Download the latest drivers from Microsoft (as said by Julian Schmuckli).
Check if your XAMPP is 64 bits(!) with Phpinfo(). If you've got 32-bit, you need different drivers.
Add the drivers to your Php.ini file and save the dll's in your php/ext-folder (question of saber tabatabaee yazdi).
For the connection, use this code:
$dbh = new PDO ("sqlsrv:Server=$server;Database=$dbname",$username,$pw);
If you add a port, use:
$server = "192.168.1.15, 51022";
Where the IP (can be hostname to) is your server and 51022 your port.

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

php with ms sql server downloading and connecting

I have a project written in php.Also,another application is written in C(sharp) with Ms Sql as the database engine. I want to fetch some data from the Ms Sql database and use it in php. I have tried many solution provided on stackover and other site, but none seems to work.Below are what I have done, maybe there is a place where i am missing something:
I Downloaded drivers(Ms Drivers for php) and loads it into the C:\wamp\bin\php\php5.5.12\ext directories.files are
php_pdo_sqlsrv_55_nts.dll
php_pdo_sqlsrv_55_ts.dll
php_sqlsrv_55_nts.dll
php_sqlsrv_55_ts.dll
Modify the php.ini by including the following in the extension area:
extension=php_pdo_sqlsrv_55_nts.dll
extension=php_pdo_sqlsrv_55_ts.dll
extension=php_sqlsrv_55_nts.dll
extension=php_sqlsrv_55_ts.dll
In fact, one of the site says I should rename by removing the "_55_xx", so that it looks like php_sqlsrv.dll.yet it is still not working.
Restart the Apache server and discovered that the included files not activated or seen when you click on the wamp monitor,navigate to the php and view the extension directory.
I have search and search,seems to be given up, but thought it better to communicate with others who can be of assistance. I currently use wamp and php version is php5.5.12. Please, I need a solution on how to get working drivers to connect my php with Ms Sql server and get data from the server seamlessly.
After much surfing the solution to the above question is as follows:
1. If you are using wamp server 64bit, you have to downgrade to wamp32bits.
2. Download the microsoft driver for php, essentially the 3.0 version.
3. Install it to your php extension directory
4. Open the php-ini file and add these two files to the extension section of the file:
extension=php_pdo_sqlsrv_53_ts.dll
extension=php_sqlsrv_53_ts.dll
Also uncomment the extension=php_pdo_mssql.dll for usage.
5. Restart the wamp server to proceed.
6. Test your connection using a blank php file with the following code:
<?php
$serverName = "192.168.1.2"; //serverName\instanceName
$connectionInfo = array( "Database"=>"xxxxxx", "UID"=>"xxxx", "PWD"=>"xxxxx");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if($conn ) {
//echo "Connection established.<br />";
}else{
echo "Error in connection";
}
?>
NB: You will need to replace xxxx with your credential. You can also use the Wamp Monitor on the desktop to activate any extension file as well.

Xampp MS SQL server PHP 5.6

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

Want to connect PHP5 to MS SQL SERVER 2005

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

Categories