0

I have the code with php using bulk insert.,I run the code and there is no error., The Problem there is no OUTPUT with this code and blank page/screen appear .. All I want to do is to have the Output with the page and with the database using this code ..

 <?php

     $dbh = odbc_connect(
           "DRIVER={SQL Server Native Client 10.0};Server=.;Database=ECPNWEB", 
           "sa", "ECPAY");




 if (($handle = fopen("c:\\tblmcwd.txt", "r")) !== FALSE) {
     while (($data = fgetcsv($handle, 4096, "|")) !== FALSE) {
         if (count($data) == 10) {
             $sql = "INSERT INTO [dbo].[tblMCWD] (
                         [ID], 
                         [ConsumerCode], 
                         [ConsumerName], 
                         [AccountStatus], 
                         [AccountNumber], 
                         [DueDate], 
                         [CurrentBill], 
                         [PreviousBill], 
                         [TotalDiscount], 
                         [TotalGrossAmountDue]
                     ) VALUES (
                         ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
                     )";

             $stmt = $dbh->prepare($sql);
             $stmt->bindValue(1, $data[0]);
             $stmt->bindValue(2, $data[1]);
             $stmt->bindValue(3, $data[2]);
             $stmt->bindValue(4, $data[3]);
             $stmt->bindValue(5, $data[4]);
             $stmt->bindValue(6, $data[5]);
             $stmt->bindValue(7, $data[6]);
             $stmt->bindValue(8, $data[7]);
             $stmt->bindValue(9, $data[8]);
             $stmt->bindValue(10, $data[9]);
             $stmt->execute();
         }
     }
     fclose($handle);
 }
 ?>
2
  • 3
    You don't echo here anything??? so there will be no output Commented Dec 5, 2012 at 7:48
  • @MarcMeesters How can I echo the data/textfile in the form if there will no successful database transaction?please help men with this matter MArc. Commented Dec 5, 2012 at 7:51

1 Answer 1

1

Try this:

....

$sql = "INSERT INTO [dbo].[tblMCWD] (
                     [ID], 
                     [ConsumerCode], 
                     [ConsumerName], 
                     [AccountStatus], 
                     [AccountNumber], 
                     [DueDate], 
                     [CurrentBill], 
                     [PreviousBill], 
                     [TotalDiscount], 
                     [TotalGrossAmountDue]
                 ) VALUES (
                     :ID, :ConsumerCode, :ConsumerName, :AccountStatus, :AccountNumber, :DueDate, :CurrentBill, :PreviousBill, TotalDiscount, TotalGrossAmountDue
                 )";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(':ID', $data[0]);
$stmt->bindParam(':ConsumerCode', $data[1],PDO::PARAM_STR);
$stmt->bindParam(':ConsumerName', $data[2],PDO::PARAM_STR);
$stmt->bindParam(':AccountStatus', $data[3],PDO::PARAM_STR);
$stmt->bindParam(':AccountNumber', $data[4],PDO::PARAM_STR);
$stmt->bindParam(':DuaDate' , $data[5],PDO::PARAM_STR);
$stmt->bindParam(':CurrentBill', $data[6],PDO::PARAM_STR);
$stmt->bindParam(':PreviousBill', $data[7],PDO::PARAM_STR);
$stmt->bindParam(':TotalDiscount', $data[8],PDO::PARAM_STR);
$stmt->bindParam(':TotalGrossAmountDue', $data[9],PDO::PARAM_STR);
$stmt->execute();

if(!$stmt){    // Check if the query executed succesfull, if not, print the data...
    $printedString = "ID: %1$s ConsumerCode: %2$s ConsumerName: %3$s"; // and so on....
    $printedString = sprintf($printedString , $data[0],$data[1],$data[2]); // and so on...
} else{
    echo "Everything executed succesfully!<br />";
}

More info can you find here: Link And here: Link 2 And here: Link 3

Use PDO::PARAM_STR for strings and PDO::PARAM_INT for an integer, and give it an try

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the help I think the binvalue function is not supported in the ODBC.,I read some articles that there are some bugs with it..so I want now is to find the equicvalent function of that bindvalue.thanks again for the reply..
I still having the same error saying that .. Fatal error: Call to a member function bindParam() on a non-object in C:\xampp\htdocs\ecpay\bulk.php on line 29
is it okay to use PDO even that I am using only ODBC?
@KristianHernanC.Manuel As far as i know, isn't it an problem. It is secure. But i'm nog an expert in it...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.