Reputation: 384
Perhaps this is the connection string to connect to an sql server
<?php
$myServer = "localhost";
$myUser = "your_name";
$myPass = "your_password";
$myDB = "examples";
?>
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
but i do not know what to input in the $myServer, $myUser and $myPass if I wanna use windows authentication
This is my Server details kindly help me please Microsoft SQL Enterprise Manager Microsoft Corporation Version: 8.0
Upvotes: 0
Views: 8032
Reputation: 2862
If you have PHP 5.3 or later, you can no longer use the ms_sql extension, according to the PHP documentation page. I'm not sure of the extent of that, but you may want to consider using PDO instead. It allows for a generic way to access various database types, including MSSQL. To connect to a MSSQL database using PDO, you first need SQLSRV, the driver, which you can download from Microsoft here. To connect, you would use the following:
$handle = new PDO("sqlsrv:Server=$server;Database=$database", $username, $password);
Above, and to answer the main part of your question, $server
is probably localhost
, and your username and password can be accessed and changed from within the Microsoft SQL Server access panel. I believe you can use "sa"
for $username
and ""
for $password
. For $database
, just put in the name of the database you want to connect to.
To query:
$queryRef = $handle->query($query);
To read results, declaring $results
as a two-dimensional associative array, the first being the result number, the second being the column name:
$results = $queryRef->fetchAll(PDO::FETCH_ASSOC);
So $results[3]['id']
would be the value of the column 'id' of the third result.
You can find more examples on the PHP documentation page for PDO here. Much of this was taken from my previous answer here.
Upvotes: 2
Reputation: 76
Your server is usually localhost, and your username and password could be changed and viewed by following this tutorial:
Upvotes: 0