Question

I have the following bulk insert script

$sql="BULK
                INSERT nibble
                FROM 'd:\nibble.csv'
                WITH
                (
                FIELDTERMINATOR = ',',
                ROWTERMINATOR = '\n',
                FIRSTROW=2
                )

                ";
mssql_query($sql);

Msg 4860, Level 16, State 1, Line 1 Cannot bulk load. The file "d:ibble.csv" does not exist.

but when i execute from sql below server management studio it works .. what is the issue

BULK
                INSERT nibble
                FROM 'd:\nibble.csv'
                WITH
                (
                FIELDTERMINATOR = ',',
                ROWTERMINATOR = '\n',
                FIRSTROW=2
                )
Was it helpful?

Solution

You need to escape the backslash with another backslash. From d:\nibble.csv to d:\\nibble.csv

Do this way..

<?php
$sql="BULK
                INSERT nibble
                FROM 'd:\\nibble.csv'
                WITH
                (
                FIELDTERMINATOR = ',',
                ROWTERMINATOR = '\n',
                FIRSTROW=2
                )

                ";
mssql_query($sql);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top