configure wamp to connect ms sql server 2008 - php

I have never connect PHP to MS sql server so getting confusion and trouble for configuring wamp to connect with sql server by following online tutorial. I have install wamp that consist of Apache Version 2.2.21 and PHP Version 5.3.8 and MS Sql server 2008 on same machine.
I downloaded the Microsoft Drivers for PHP for SQL Server(SQLSRV20.EXE). and extracted the file to D:\wamp\bin\php\php5.3.8\ext. Then I opened the php.ini file from wamp icon tray and provide the extension path as extension=php_sqlsrv_53_ts_vc9.dll and extension=php_sqlsrv_53_nts_vc9.dll.
I have put php file name testsqlserver.php in www root folder of wamp which code is shown below:
<?php
$server = 'mypc/SQLEXPRESS';
$link = mssql_connect($server,'sa','password');
if(!$link)
{
die('something went wrong');
}
?>
When I called testsqlserver.php through browser as localhost:8080\testsqlserver.php. It shows the error:
Fatal error: Call to undefined function mssql_connect() in D:\wamp\www\connectsqlserver.php
am I doing wrong way? or is there anything more to do for this.I have gone through different online search but unable to get the exact solution for this. Would someone help me, it would be great appreciation

You have to edit your php.ini file located within the WAMP directory. There should be a few lines in there for loading the MS SQL extension but they are commented out; all you need to do is uncomment those lines and restart Apache.
I'm using XAMPP and the lines within my php.ini that I have to uncomment are:
;extension=php_mssql.dll
;extension=php_pdo_mssql.dll

Microsoft Drivers for PHP for SQL Server which you have downloaded , support sqlsrv_connect() to establish connection with sql server database
You should use sqlsrv_connect() function to connect with sql server , mssql_connect is depreciated
you can get full list of function and their description form following link
http://msdn.microsoft.com/en-us/library/cc296152%28SQL.90%29.aspx

I do not currently use wamp, but I think you should enable PHP extensions for this. Click on wamp icon in status bar and enable php_mssql and php_pdo_mssql extensions, then restart apache service.

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.

sasql_connect(): SQLAnywhere: [-100] Database server not found

it's about more than one full day that i started sqlanywhere and i'm so interested to use it,
i worked before with sqlsrv for ms sql server and connection via php ,
but i have problem for connecting php to sqlanywhere
here is the warning message when i try to run test.php
Installation successful Using php-5.6.0_sqlanywhere.dll
Warning: sasql_connect(): SQLAnywhere: [-100] Database server not found in C:\xampp\htdocs\test.php on line 44
Connection failed
$conn = sasql_connect( "UID=DBA;PWD=sql" );
if( $conn ) {
echo "Connected successfully\n";
sasql_disconnect( $conn );
} else {
echo "Connection failed\n";
}
I'm using xampp server php 5.6 and sqlanywhere 17 developer edition.
already i downloaded the php extension and copied on ext and also added the line in php.ini (extension=php-5.6.0_sqlanywhere.dll)
demo database i ran it with cmd : dbeng17 "%SQLANYSAMP17%\demo.db".
via cmd i tried this also :
C:>dbping -d -c "uid=dba;
SQL Anywhere Server Ping U
Connected to SQL Anywhere
Ping database successful.
but when i try via php it says: Warning: sasql_connect(): SQLAnywhere: [-100] Database server not found in C:\xampp\htdocs\test.php on line 44
Connection failed
please someone tell me what is the problem ?
thank you very much.
Your PHP installation may have multiple files similar to php.ini. Make sure you are modifying the php.ini file listed in phpinfo().
- A web server such as Apache, IIS, or any web server that supports
PHP.
- PHP installed on the same computer as the web server.
- SQL Anywhere installed on the same computer as the web server.
- The client software can be used as well. SQL Anywhere PHP extension
Refrance : https://wiki.scn.sap.com/wiki/display/SQLANY/Getting+Started+with+SAP+SQL+Anywhere+and+PHP
It solved for me when I installed and used it on another system , I don't know I tried first on a system that MSSQL server was install and I couldn't run it and tried on another system that mssql server was not installed and solved :)
sorry for being late to answer and thank you very much for those who took time to help me.

SQL server error: Unable to connect to your database server using the provided settings

Again I am here with an error, i have connected my PHP with SQL server from an IP Address and it works properly in my local PC. but when i transfer my source codes to my client PC it gives below error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:/xampp/htdocs/SAT_POS/system/database/DB_driver.php
Line Number: 436
but actualy i have included the extension also and set in php.ini, see below:
extension=php_sqlsrv_56_ts.dll
extension=php_sqlsrv_54_ts.dll
the above two lines are included in the php.ini file and the extension directory is also the default one, see below:
extension_dir="C:\xampp\php\ext"
and in CI database code I configured like below :
You have to pick ONE SQL Server database extension ONLY.
You have also loaded one extension that is compiled for PHP 5.4
php_sqlsrv_54_ts.dll
AND one that is compiled for PHP 5.6
php_sqlsrv_56_ts.dll
Pick the ONE extension that matches your currently runnning PHP version
Also did you load the SQLServer client software on your clients PC.
At last with the help of the stack genius who commented on this I have done the work!
Just installed ODBC DRIVER for SQL SERVER on the windows!

How to connect to MySQL using PHP PDO in easyphp 16.1.1

I'm trying to move over to PHP7 and use the latest EasyPHP but I can't for the life of me figure out how to connect to MySQL using the PDO
I've set up a working directory:
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\TechMexv3 with cURL
I've installed all my database tables in phpMyAdmin which has worked fine
I'm now trying to connect with the following:
$DBH = new PDOEx('mysql:host=localhost; dbname=techsmex; charset=utf8mb4', 'root', '');
And I'm getting the error:
could not find driver
Do I need to install a driver from somewhere that doesn't come with EasyPHP?
In EasyPHP Devserver 16.1.1, the default configuration file for php (php.ini) has the PDO MySQL extension disabled by default.
You have to enable it and restart your server before you can connect to your database.
In order to do this,
Go to your EasyPHP Devserver Dashboard;
Stop your HTTP Server in case it is running;
Select the version you are using for PHP in the left panel;
Open the corresponding folder for your PHP.
In it, is your php.ini file. Open the file with your preferred text editor, and search for ;extension=php_pdo_mysql.dll
Simply remove the semicolon in the beginning so the extension gets activated upon restarting of the HTTP server. Go to your dashboard's main page, and restart the HTTP server.

"Call to undefined .. mssql_connect" when using PHP in IIS?

May is ask you about how to connect to Microsoft SQL server 2005 enterprise using PHP.
I am using Appserv 2.5.10 ( Apache 2.2.8, PHP 5.2.6) and SQL server 2005
After I place the extension download from this link :
http://www.microsoft.com/en-us/download/details.aspx?id=20098
enable the php.ini file by adding these lines.
extension=php_pdo.dll
extension=php_sqlsrv_52_ts_vc6.dll
extension=php_pdo_sqlsrv_52_ts_vc6.dll
Restart Apache using this code to connect
$link = mssql_connect($server, $user, $pass);
Error shown in browser is
Fatal error: Call to undefined function mssql_connect() in G:\AppServ\www\testmssql_connect.php on line 12
can anyone help me ?
NOTE: i am using windows server 2003 and i don't found this OS in OS supporting list of Microsoft Driver 3.0 for PHP. Is this issue cause the problem ?
Look at this link:
PHP Fatal error: Call to undefined function mssql_connect()
1) Check your PHP.INI file's extension_dir
2) Make sure you copied your .dlls into that directory (for example, into C:\PHP\ext").
3) Create a dummy page to call phpinfo();. Display the page in a browser. Make sure you see entries for "sqlsrv".
'Hope that helps!

Categories