Tuesday, October 4, 2011

mssql server conncet to linux php

now install in linux machine(fedora/centos)

yum install freetds

and

yum install php-mssql (if not work then go menu system -> administartor add/remove software and search mssql and select php-mssql)

open
/etc/freetdsconf

and add the last

[conncetmssql]
host = 192.168.1.5
port = 1433
tds version = 4.2

> service httpd restart

example:

<?php
if (function_exists('mssql_connect')){
echo "Okay, function work";
} else {
echo "php-mssql not installed";
}

if(extension_loaded("mssql")) {
echo "MSSQL is Loaded<br>";
}
else {
echo "MSSQL not loaded<br>";
}

// Connecting, selecting database
$link = mssql_connect('conncetmssql', 'username', 'password') or die('Could not connect: ' . mssql_get_last_message());
echo 'Connected successfully';
mssql_select_db('yourdatabasename') or die('Could not select database');

echo "select db";
// Performing SQL query
$query = 'SELECT * FROM tablename';
$result = mssql_query($query) or die('Query failed: ' . mssql_error());

// Printing results in HTML
echo "<table>\n";
while ($line = mssql_fetch_array($result, MSSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mssql_free_result($result);

// Closing connection
mssql_close($link);
?>

Configure a server alias to use TCP/IP sockets

Note To configure a server alias to use TCP/IP sockets, you must provide the server name and the TCP/IP port number.

1. Determine the TCP/IP port number of the instance of SQL Server.

SQL Server 2005
1. Open SQL Server Configuration Manager, and then expand SQL Server 2005 Network Configuration.
2. Click Protocols for InstanceName, and then double-click TCP/IP in the right panel.

Note InstanceName is a placeholder for the named instance of SQL Server 2005.
3. On the Protocol tab, notice the value of the Listen All item.
4. Click the IP Addresses tab:
* If the value of Listen All is yes, the TCP/IP port number for this instance of SQL Server 2005 is the value of the TCP Dynamic Ports item under IPAll.
* If the value of Listen All is no, the TCP/IP port number for this instance of SQL Server 2005 is the value of the TCP Dynamic Ports item for a specific IP address.
Note If the value of the TCP Dynamic Ports item is not set, you must set it yourself. For more information about how to configure a server to listen on a specific TCP port, visit the following Microsoft Developer Network (MSDN) Web site: http://msdn2.microsoft.com/en-us/library/ms177440.aspx (http://msdn2.microsoft.com/en-us/library/ms177440.aspx)
5. Click OK.

or more detail bellow two link

1. http://support.microsoft.com/kb/265808
2. http://msdn.microsoft.com/en-us/library/ms177440.aspx

how to see xml preview in browser php

xml preview view in browser $xml = new DOMDocument('1.0', 'UTF-8');                 $xml->preserveWhiteSpace = false; ...