What is a way for accessing a SQL database server?

Asked By -10 points N/A Posted on -
qa-featured

Database base is most popular in transferring data. What is the best way to access a SQL database server?

SHARE
Best Answer by bonifacekimeu
Best Answer
Best Answer
Answered By 0 points N/A #120126

What is a way for accessing a SQL database server?

qa-featured

Hi dear,

The Best way is via a PHP script.

For instance:

<? PHP
$myServername = "localhost";
$myUsername = "your_Username";
$myPassword = "your_password";
$myDB = "example";

//Connect to the database
$dbhandle = mssql_connect($myServername, $myUsername, $myPassword)
  Or die ("Couldn't connect to SQL Server on $myServer");

//Select a database to work with

//Assuming you have the following database
$selected = mssql_select_db($myDB, $dbhandle)
  Or die ("Couldn't open database $myDB");

//Declare the SQL statement that will query the database
$query = "SELECT id, name, year,make ";
$query .= "FROM cars ";
$query .= "WHERE name='Toyota'";

//Execute the SQL query and return records
$result = mssql_query($query);

$numRows = mssql_num_rows($result);
Echo "<h1>" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned </h1>";

//Show or display the results
While ($row = mssql_fetch_array ($result))
{
  Echo "<Li>" . $row["id"] . $row["name"] . $row["year"] . "</li>";
}
//Close the connection
mssql_close($dbhandle);
?>

The alternative is using DNS 'Data Source Name'

<? PHP

//Connect to a DSN "myDSN"
$conn = odbc_connect ('myDSN','','');

If ($conn)
{
  //The SQL statement that will query the database
  $query = "select * from cars";
  //Perform the query
  $result=odbc_exec($conn, $query);

  Echo "<table border="1"><tr>";

  //Print field name
  $colName = odbc_num_fields($result);
  For ($j=1; $j<= $colName; $j++)
  { 
    Echo "<th>";
    Echo odbc_field_name ($result, $j );
    Echo "</th>";
  }

  //Fetch the data from the database
  While (odbc_fetch_row ($result))
  {
    Echo "<tr>";
    For ($i=1; $i<=odbc_num_fields ($result); $i++) 
    {
      Echo "<TD>";
      Echo odbc_result ($result, $i);
      Echo "</TD>";
    }
    Echo "</tr>";
  }

  Echo "</td> </tr>";
  Echo "</table >";

  //Close the connection
  odbc_close ($conn);
}
Else echo "No connection";
?>

Hope it is helpful. Let me know your progress.

Thanks.

Answered By 590495 points N/A #120127

What is a way for accessing a SQL database server?

qa-featured

Here are some of the possible ways of optimizing database access in an SQL server. If you use the TSQL code in your application, transfer it into the database server. Transferring SQL from the application to the server and then applying them by means of views, triggers, stored procedures, or functions will help you remove any duplicate SQL. This also guarantees re-usability of the TSQL codes. Applying all TSQL codes via database objects will help you easily examine TSQL codes.

This will then let you search for ineffective codes that cause slow performance. It also lets you handle TSQL codes from a central point. It would also be a great advantage to re-factor your TSQL codes to use some of the advanced indexing techniques.

Answered By -10 points N/A #120128

What is a way for accessing a SQL database server?

qa-featured

SQL Server is the best way to create a fast service to a website. I am also kin to SQL Server. However, I also faced trouble like Michael San Juan in accessing SQL database server. Now I have come out of unease to entrance my own SQL server. I am really very thankful to everyone on this page. But I think, Sharath Reddy is the best of all. Really, you’re great. Your easy techniques helped me to solve my issue now. You gave more simple ways on how to fix the problem in SQL server. You are giving the flow in how to access the SQL server easily to the user. Thanks Sharath. Splendid.

Related Questions