Newbie of newbie: mssql query failed

Newbie of newbie: mssql query failed

ayu106ayu106 Posts: 2Questions: 0Answers: 0
edited December 2013 in Editor
Hi,

I am really new to database system. I just understand on the surface such as the relationship between html, php, and sql.
But now, I am trying hard to understand the script how to connect them altogether to create a web page.
Straight to the point, I am writing code to display table from an mssql database server in php. I have tried to write and follow many php-mssql tutorial on the net. But still get the warning and error result. The connection seems success. But then appear two warnings on the browser page:

Warning: mssql_query() [function.mssql-query]: message: Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query. (severity 16) in C:\xampp\htdocs\webtools\sql_test.php on line 18

and

Warning: mssql_query() [function.mssql-query]: Query failed in C:\xampp\htdocs\webtools\sql_test.php on line 18

Please take a look at the code below, Your help is really aprreciated :)

<?php
// Connect to MSSQL
include_once "perform_table.php";

$myDB = "table1";
$db = mssql_connect('xx.xx.xx.xxx', 'server_name', 'server_pass');
if (!$db) {
die('Something went wrong while connecting to MSSQL');
}
mssql_select_db($myDB, $db);

$sql = "SELECT ID, NAME , Address FROM [xx.xx.xx.xxx].table1.dbo.table201212";

$rows = 1;
$arr=null;

//execute the SQL query and return records
$result = mssql_query($sql);

if($result!=null){
while ($row=mssql_fetch_array($result)) {

$arr[$rows]["field_1"]=$row["ID"];
$arr[$rows]["field_2"]=$row["Name"];
$arr[$rows]["field_3"]=$row["Address"];

$rows++;
}
}

if($arr!=null){

create_table_exception($arr);
}


?>


NB: there is no problem with the file included (perform_table.php) and the function (create_table_exception($arr))

Thank you

Replies

  • ayu106ayu106 Posts: 2Questions: 0Answers: 0
    edited December 2013
    perform_table.php:

    <?php
    function create_table_exception($arr){
    $tempTable = "

    No.
    ID
    Name
    Address
    ";
    for ($idx = 1;$idx <= count($arr);$idx++) {
    if($idx%2==0){
    $tempColor = "style=\"background-color: #ccccc0;\"";
    }else{
    $tempColor = "style=\"background-color: #FFFFF;\"";
    }
    $tempTable .= "";
    $tempTable .= "".$idx."";
    $tempTable .= "".$arr[$idx]["field_1"]."";
    $tempTable .= "".$arr[$idx]["field_2"]."";
    $tempTable .= "".$arr[$idx]["field_3"]."";
    $tempTable .= "";
    }
    $tempTable .= "";
    echo $tempTable."

    ";
    }
    ?>
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    I'm afraid I can't offer any help with generic PHP issues. You'll be better offer asking in StackOverflow or similar, where them might be an MSSQL / PHP expert available (which I am not!).

    Allan
This discussion has been closed.