I have my wordpress page and I want to connect with an external MS SQL SERVER DB.
I am using a plugin that allows me to put PHP CODE in there. This is my code:
$serverName = "192.168.2.3";
$connectionInfo = array( "Database"=>"v3v", "UID"=>"sa", "PWD"=>"1234567");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
The problem is that sqlsrv_connect is not activated. I have been looking for information and it seems that I need some drivers for my php version(5.6). I got the .exe file that install .dll(the drivers) but I don't know where to put it. I mean, Where is my php configuration with wordpress?
With xampp it was located at PHP/ext.
If you have another solution to do this simply query I would appreciate it because I know that Wordpress likes to work with MySql but I have to connect with MS SQL SERVER.
Related
I'm using WampServer and PHP7. I'm trying to connect to a MS Access database that I created and named "db_operation.accdb". I moved that database to "C:\wamp\www\Operation-Monitor\db". I can't seem to figure out how to connect to it. Although, I can perfectly see it when I browse "127.0.0.1\Operation-Monitor\db". However, I'm clueless about connecting it.
$mysql_user = "";
$mysql_password = "";
$mysql_database = "127.0.0.1\\Operation-Monitor\\db\\db_operation.accdb";
$db = odbc_connect("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=$mysql_database;Persist Security Info=False;", $mysql_user, $mysql_password) or die ("Couldn't find any databases.");
I'm getting the following error when I execute my code:
https://i.imgur.com/gERtbhD.png
To get a seamless portable database storage which works with office products as well as server based i suggest to have a look at SQLITE. The database is inside a single file which makes it highly portable between devices. It is open source, supportetd on many OS and has working connectors foe nearly anything possible. In your case you can have for example a fast ado connector in the WAMP server and on Excel and friends a native VBA connector.
I have a SQL server on MS azure. Using a php file and some basic select statements (eg. select * from table) I have been able to grab data from the database, so I know my details are correct.
However when I put a connect statement in any other files the page appears blank. For example, any form submission pages.
This is the connect statement I have:
<?php
$myServer = "hostname";
$myUser = "username";
$myPass = "password";
$myDB = "dbname";
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
?>
I'm sure it's probably something simple but I have tried loads of different ways and nothing seems to work, I don't even get an error message to work with.
Could someone please help?
Uncomment this line in your php.ini.
extension=php_mssql.dll
To locate your php.ini file, add this code below at the top of your php script
<?php phpinfo(); ?>
By default, Azure environment doesn't install php_mssql.dll extension, it installs php_sqlsrv.dll instead.
You can leverage Console tool in Azure portal and execute php -m to check all the preinstalled modules in Azure PHP runtime:
You can use PDO in PHP to handle sql server database, such as the following connection test:
try {
$conn = new PDO("sqlsrv:server = tcp:garysql.database.windows.net,1433; Database = garymbdata", "gary", "QWEasdzxc123");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
print("Error connecting to SQL Server.");
die(print_r($e));
}
Additionally, we can configure PHP configuration settings on Azure Web App beside modifying php.ini directly. Also we can install mssql.dll extension on Azure Web App if you insist on.
Please refer to https://learn.microsoft.com/en-us/azure/app-service-web/web-sites-php-configure for more info.
I am working on a PHP project where I have to create an API to fetch data from client's MS SQL server. I am doing it as-
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server_ip;Database=$databse;", $username, $password);
Its working on my localhost(might be because I have SQL Server install on my system, but not sure). But does not work on hosting server. It gives error-
[unixODBC][Driver Manager]Can't open lib 'SQL Server Native Client 10.0' : file not found
I have even tried -
$serverName = $server_ip;
$connectionInfo = array( "Database"=>$database, "UID"=>$username, "PWD"=>$password);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$conn does not return anything.
Is there any other alternative?
I have even got odbc driver install.
There is an alternative (extension) called php-sybase. I am using it successfully to connect to various (versions) MSSQL databases with different php versions, to mention just: 5.6 and 7.0.
I need the guidance help on ODBC connection string in PHP, which I am using to connect to MS SQL Server.
<?php
$server = 'UKEMO03';
$database = 'mtpFetch';//the database to connect to
$user = 'shoabg';// the user has PERMISSIONS AT THE DATABASE
$pass = 'Shsx12x';//and here the user's password
$dsn = "Driver={SQL Server};Server=$server;Database=$database;";
$connect = odbc_connect($dsn, $user, $pass);
?>
Above code works treat, but i have a requirement of not to specify the username and password and use the connection string with Integrated Security. I can't find anything on internet and I can't change the connection string method because I've completed most of my work and by adapting another connection method will require a massive change in a code in theory its not an option for me.
Is there a way we can create Integrated Security connection to connect MS SQL Server in PHP using ODBC
Please help i don't know what to do
This will connect you to the ODBC master database (cathalog).
I did not succeed to connect to another database. There is an option for default database in the configuration of ODBC SDN, but has no effect
("Chenge the default database to").
$this->dbHandle = odbc_connect("Driver={SQL Server};Server=localhost;Integrated Security=SSPI", '', '');
If you use PHP ini make sure you use:
mssql.secure_connection=On
On the database server, make sure you have Windows Authentification associated with your login username
Using the PHP drivers from Microsoft, we cannot connect using either Windows Authentication or SQL Server authentication. We use the following PHP code:
$serverName = "(A\B)";
$connectionInfo = array( "UID"=>"u1",
"PWD"=>"p1",
"Database"=>"db1");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
In a nutshell the php sql server stuff is terrible.
The only reliable solution (and I am forced to use SQL Server 2008 here for a very complex project) is using PHP ADODB.