Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Kristina Petravičiūtė
Kristina Petravičiūtė
11,270 Points

Connect MSSQL with PHP

How can I connect Microsoft Sql database using Php? It would be perfect if I could do this with Zend framework. :) I'm working with PhpStorm

3 Answers

Jacobus Hindson
Jacobus Hindson
14,429 Points

This is an example from the PHP Manual for mssql_connect.

<?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');
}
?>

Check out more information here php.net

Hope that helps.

Kristina Petravičiūtė
Kristina Petravičiūtė
11,270 Points

I stil can not to connect... In web browser I get message: Could not connect: Login failed for user 'test-intranet_fltechnics_com'."

My code:

<?php

$server = 'FSQL'; $username = 'test-intranet_com'; $password = 'xxxxxxxxx';

$db = mssql_connect($server, $username, $password); if (!$db) { die('Could not connect: ' . mssql_get_last_message()); } echo 'Connected successfully'; mssql_close($db);

?>

How can I fix this?