How to connect to an external BBDDD MS SQL

How to connect to an external BBDDD MS SQL

If you want to connect from your web hosting to an external MS SQL database, you can use the mssql_connect() function.
Below we show an example code to use a connection with mssql_connect.
  
//replace the values with those of your server.
$myServer = "SERVER";
$myUser = "USER";
$myPass = "PASSWORD";
$myDB = "DATABASE";
//database connection
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
// or die("Connection failed to $myServer");
or die('MSSQL error: ' . mssql_get_last_message());
//select the database
$selected = mssql_select_db($myDB, $dbhandle)
or die("Cannot open database $myDB");
//execute the SQL query
$query = "SELECT top 1 * ";
$query .= "FROM test ";
//run the SQL query and display the results
$result = mssql_query($query);
$numRows = mssql_num_rows($result);
echo "
" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned
";
while($row = mssql_fetch_array($result))
{
echo "
" . $row["idVenta"] . $row["idNlinea"] . "
";
}
//close the connection
mssql_close($dbhandle);
?>

This code is used to check that the connection to the database is successfully established.


For more information, you can contact us.
    • Related Articles

    • How to connect to a database with MySQL Workbench

      Below we explain step by step how to establish a connection to your MySQL database using MySQL Workbench, including the necessary screenshots to guide you during the process. 1. Download and installation of MySQL Workbench MySQL Workbench is a free ...
    • How to connect via FTP using WinSCP

      To upload your website to your cdmon hosting account, you need an FTP client. An FTP client is special software that connects to the web server using the FTP communication protocol and allows you to manage your website as if it were Windows Explorer. ...
    • How to connect via FTP via webFTP

      To upload your website to your hosting account at cdmon, you need an FTP client. In the cdmon Control Panel, you have an intuitive web manager that allows you to perform the most common operations. The "WebFTP" service features allow you to access ...
    • How to connect via FTP using FileZilla

      Affordable hosting To upload your website to the contracted hosting service, you must use an FTP client program. There are many programs that can help you; one of the most popular is FileZilla. Connecting to the FTP service through a client requires ...
    • How to connect to MySQL via SSH

      Any hosting that has SSH access enabled can connect to MySQL via console. To do so, you must use the following command: mysql -h ipweb -u databaseuser -p -h: In this option, enter the web IP of the hosting. You can check the IP in the Server ...