Connect to SQL server 2014 management studio with PHP - php

Is there a way to connect to Microsoft's SQL server 2014 management studio with PHP?
I was able to connect to the same database with ASP.NET, but I'm not seeing anything online on how to connect to that type of database with PHP. All I'm seeing is Mysql, not SQL server 2014 management studio with PHP.
this is what I have so far to connect via PHP
<?php>
$myServer = "LALA";
$myDB = "LGWeb";
// connection to database
$dbhandle = msql_connect($myServer)
or die("couldn't connect to SQL Server on $myServer");
// select database to work with
$selected = mssql_select_db($myDB,$dbhandle)
or die("couldn't connect to database - $myDB");
if (isset($_POST['submitted'])){
include('')
}// end of main if
?>
I changed my database names and server name in code above. But that's the basic idea. Just trying to connect to it with PHP.
This is how I connected to it with ASP.NET
<connectionStrings>
<add name="LALAConnectionString" connectionString="Data Source=LALA;Initial Catalog=LGWeb;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>

Related

How to connect to MS Access database in PHP7?

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.

PHP remote access MSSQL Server

I was trying to use php to remote connect to MSSQL database in other server. But at the end it show error
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: xxx.xxx.xxx.xxx in xxxxxxx
Here is my code
<?php
$myServer = "xxx.xxx.xxx.xxx";
$myUser = "user";
$myPass = "password";
$myDB = "database";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
?>
I have try the login with microsoft SQL Server Management Studio and it can work and login so I don't that having problem with the allow remote connection access.
Btw.. I just access it from XAMPP Localhost. I'm not sure is this effect or not.
Thank you in advanced for whose help.
First guess:
Your SQL-Server is not listening to TCP/IP. Enable that protocol in configuration manager. Restart the server process.
Second guess:
A firewall is blocking the access. Enable access to TCP Port 1433.
Third guess:
driver problems
mssql driver need that special version of the ntwdblib.dll.
Depending on you php version it's not there.
Better switch to the new driver "sqlsrv".
https://www.microsoft.com/en-us/download/details.aspx?id=20098

(php) could not connect to the MSSQL 2008 on the vps server

I have a google vps server with a database MSSQL 2008 r2 . on a computer at home I can not connect to the database with php script but when filled ip,port tool "SQL Server Management Studio" it connects successfully . please help me fix it, I seem to be going crazy :(
Image SQL Server Management Studio 2008 r2
here is my php code
<?php
$myserver = "xx.xx.xx.xx,1433";
$myuser = "sa";
$mypass = "123456";
$mydb = "muonline";
//connection to the database
$dbhandle = mssql_connect($myserver, $myuser, $mypass)
or die("couldn't connect to sql server on $myserver");
//select a database to work with
$selected = mssql_select_db($mydb, $dbhandle)
or die("couldn't open database $mydb");
//close the connection
mssql_close($dbhandle);
?>
I tried to change $myserver with the value:
xx.xx.xx.xx:1433
xx.xx.xx.xx\\instance-1,1433
xx.xx.xx.xx:1433\\instance-1
xx.xx.xx.xx
xx.xx.xx.xx\\instance-1
always notify Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server

How to connect to a remote computer running a sql database via php

I am running an apache webserver on a server on my local network.
I have a microsoft SQL server 2008 r2 database running on a different machine on the same network. My webserver is hosting a lot of pages, and are all fine and can be accessed locally and externally. However, when I try to connect to the SQL database using php, I get hit with the following error.:
Failed to connect to MySQL: No connection could be made because the target machine actively refused it.
I am at a total loss at this point as I have opened port 1433 and have spent hours trying to figure this out.
The code that I am using is a very basic connect script:
<?php
// Create connection
$con = mysqli_connect("mycomputer", "myname", "password", "my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
If anyone can help, I would sincerely appreciate it as iIam about to give up on this project!!!
Thank you in advance.
As i understand - you use MS SQL , so you must use mssql_connect not as mysqli_connect
Check here
Cause its another database and another driver (extension ) using to connect

How to do PHP to MS SQL connection?

I'm using xampp and my php version is php5.5.6 in WIN-7 os. I want to connect the MS SQL Server from my PC. I'm having MSSQL SERVER in my LAN. how to do that, I'm new to PHP?
Right from the manual - http://www.php.net/manual/en/function.mssql-connect.php
<?php
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$server = 'KALLESPC\SQLEXPRESS';
// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
?>
If this code does not work, then make sure you can ping the database server from the web server.

Categories