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.
Related
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.
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.
I'm a newbie at PHP, and coding in general, however I'm attempting to set up a simple user login/registration page using a MySQL database via phpmyadmin. After hours of trawling through forums etc, I could only find outdated information with no relevance to my specific issue.
My set up is as follows:
XAMPP v3.2.2, phpMyAdmin (Apache/2.4.18 (Win32) Open SSL/1.0.2e, PHP/7.0.3 with mysqli PHP extension/ Maria DB Server Type) & Dreamweaver CC.
I have set up a new site & a new server (following various online tutorials that show the same method) but when I attempt to define a connection via recordset, it displays the error message:
"Your PHP server doesn't have the MySQL module loaded or you can't use the mysql_(p)connect functions."
I have the MySQL module loaded and it's working fine as I am able to connect to phpmyadmin. Apache module is loaded and it's working fine as I am able to connect to my localhost in the web browser. Details for testing server have been set up in C:\xampp\htdocs\mysite and changed to PHP/MySQL server model.
The database and tables have been created in phpmyadmin and ready to go, however I just can't connect to them through Dreamweaver CC.
I've tried changing information in config.inc.php, tried changing extension_dir path to mysqli.dll in php.ini (which is in C:\xampp\php\ext) and also uninstalled and reinstalled XAMPP twice.
I believe that my phpmyadmin and XAMPP server are working fine, however I just can't seem to have any success linking it to my php pages in Dreamweaver CC.
Am I missing anything obvious?
Any help/clarity would be greatly appreciated as I'm currently losing all hope! Thank you!
i know this is a little old but i was able to fix the problem.
xampp by default only has MySQLi dll activated. go to the php ini file and uncomment the MySQL dll and restart the Apache server.
this worked for me. also cs6 need the database extension installed.
The error says "Your PHP server doesn't have the MySQL module loaded or you can't use the mysql_(p)connect functions."
In php7 mysql_* has been deleted you have to use mysqli or PDO instead.
You can read more about hereenter link description here
The error shows that you are using mysql_* extension. Your code must look like these: mysql_connect("localhost", "user", "password");. You have to change this to $conn = new mysqli("localhost", "user", "password", "database");. Check this link to review how to change your
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");
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.