PHP 5.3 connecting to MSSQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shahab.fm
Forum Newbie
Posts: 2
Joined: Thu Sep 06, 2012 8:34 am

PHP 5.3 connecting to MSSQL

Post by shahab.fm »

Hi,

I am struggleing to connect to a MS SQL database through PHP. My php version is 5.3.10-1ubuntu3.2 and as u might guess from the version name it runs on an Ubuntu machine.

I found out that PHP 5.3 doesn't directly support connecting to MS SQL and I need to install a driver from MS for it. Could this be installed on Linux ? Is it a stable way to connect to MS SQL ? Is there any better way to do so ?

Thanks alot for your help,

Shahab
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP 5.3 connecting to MSSQL

Post by Celauran »

Do you have php5-sybase installed?
shahab.fm
Forum Newbie
Posts: 2
Joined: Thu Sep 06, 2012 8:34 am

Re: PHP 5.3 connecting to MSSQL

Post by shahab.fm »

Hi,

No I didn't have it installed. Now I have and I have followed this tutorial with no luck ... :banghead: :banghead: :banghead: :banghead:
http://jamesrossiter.wordpress.com/2011 ... l_connect/

The server gives an error on running first line ($server = ‘my.server.ip:1433\DATABASEINSTANCE’;) which ofcourse I updated with my own information

Code: Select all

<?php
    ini_set(‘display_errors’, 1);
    $server = ‘myIP,1433’;
    $link = mssql_connect($server, ‘user’, ‘pass’);
/*
    if (!$link) {
    die(‘<br/><br/>Something went wrong while connecting to MSSQL’);
    }
    else {
    $selected = mssql_select_db(“ob_reportingDB”, $link)
    or die(“Couldn’t open database databasename”);
    echo “connected to databasename<br/>”;

    $result = mssql_query(“SELECT * FROM [ob_reportingDB].[dbo].[PRODUCTION_HEADER]”);

    while($row = mssql_fetch_array($result))
    echo $row["name"] . “<br/>”;
    }
*/
?>
<html>
<head>
</head>
<body>
Yohohohohohohohoho
</body>
</html>

As you see even the deactivated code (only the 2nd line) makes the code to crash ...
Post Reply