user3026933
user3026933

Reputation:

mssql bulk insert not working while executing from php

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
                )

Upvotes: 2

Views: 1922

Answers (1)

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);

Upvotes: 1

Related Questions