views:

83

answers:

1

Hello all,

Does file_get_contents maintain line breaks? I thought it did but I have tried this:

if($conn){

    $tsql = file_get_contents('scripts/CreateTables/SLR05_MATCH_CREATETABLES.sql');

    $row = sqlsrv_query($conn, $tsql);

    print_r(sqlsrv_errors());

}

The errors I get is that SQL Server complains that there is incorrect syntax. I get the same errors when I run the SQL Script without any line breaks, which suggests file_get_contents removes them?

When I run the script normally (open the file in SQL Server Management Studio) and execute it, it works perfectly.

So is there something that I can use that maintains line breaks etc? Or is there another problem here in using queries from a file with the SQL Server PHP Driver from Microsoft?

Thanks all for any help

+2  A: 

file_get_contents() does preserve the file. Perhaps your file contains the wrong "type" of line-breaks? Linux -vs- Windows style?

Also, I'm not familiar with sqlsrv_query() ... can that be used to run multiple queries (as a script might), or only single queries, one at a time?

anonymous coward
You might have a point there, I am not sure if sqlsrv_query() can execute multiple queries. Finding out now...
Abs
No it can not! Thank you for suggesting that, I will have to break up the script into queries or put in an identifier to let me know when a new query starts/end etc.
Abs