Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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?