Jump to content

kk4iku

New Members
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral

About kk4iku

  • Rank
    Newbie
  1. I am reading a file and get the information from it I need to update my SQL SERVER but I don't know how to get the values into the sql server update statement. I use the below code to read the file and get the array. With help from an earlier post, I can get the Key value into my sql and it works fine but now I need the key value and the other values in an update statement. This code does a select and shows the order numbers.I will change the select to an update statement.How do I get item1 and item 2 into the sql update statement? Update statement needed: update data.dbo.SalesOrders set status="Item2 from array", assignment=""Item1 from array" where ompsalesorderid in ($key_string) My code: <?php $lines = []; $fp = fopen('CCDATA.TXT', 'r'); while (!feof($fp)) { $line = fgets($fp); $index = substr($line, 69, 5); if(substr($line, 117, 2)=='AA' || substr($line, 117, 2)=='AC'){ $lines[$index] = ['item1' => substr($line, 91, 10), 'item2' => substr($line, 117, 2)]; $key_string = implode(',', array_keys($lines)); } } //print_r($lines); fclose($fp); $sql_update="select ompsalesorderid from data.dbo.SalesOrders where ompsalesorderid in ($key_string)"; $connect = odbc_connect("removed"); $result = odbc_exec($connect, $sql_update); if(!$result){ exit("Error in SQL"); } while ($row = odbc_fetch_array($result)) { $orderid=$row['ompsalesorderid']; echo $orderid; echo "<br>"; } odbc_close($connect); ?> output from the current code: 48580 48585 48587 48588 48592 48593 output from a print_r(lines): Array ( [48588] => Array ( [item1] => 172689364 [item2] => AA ) [48580] => Array ( [item1] => 172689365 [item2] => AA ) [48592] => Array ( [item1] => 172689916 [item2] => AA ) [48587] => Array ( [item1] => 172689366 [item2] => AC ) [48597] => Array ( [item1] => 172680495 [item2] => AA ) [11238] => Array ( [item1] => 172680482 [item2] => AA ) [48593] => Array ( [item1] => 172683140 [item2] => AA ) [48594] => Array ( [item1] => 172683141 [item2] => AA ) [48598] => Array ( [item1] => 172683142 [item2] => AA ) [48603] => Array ( [item1] => 172686160 [item2] => AA ) [48585] => Array ( [item1] => 172686152 [item2] => AA ) [48601] => Array ( [item1] => 172686162 [item2] => AA ) [48615] => Array ( [item1] => 172693602 [item2] => AA ) [48618] => Array ( [item1] => 172693603 [item2] => AA ) [48621] => Array ( [item1] => 172696837 [item2] => AA ) [48623] => Array ( [item1] => 172696838 [item2] => AA ) [48625] => Array ( [item1] => 172696839 [item2] => AA ) [48628] => Array ( [item1] => 172699180 [item2] => AA ) [48629] => Array ( [item1] => 172699181 [item2] => AA ) [48631] => Array ( [item1] => 172699182 [item2] => AA ) [48636] => Array ( [item1] => 172692202 [item2] => AA ) [48632] => Array ( [item1] => 172692204 [item2] => AA ) [48633] => Array ( [item1] => 172692205 [item2] => AA ) [48634] => Array ( [item1] => 172692206 [item2] => AA ) [48635] => Array ( [item1] => 172692207 [item2] => AA ) ) 11238
  2. so this message is from the FTP server "ftp_get(): Requested action not taken. Message not found.". can I hide it so the user only gets my message?
  3. I am downloading a file from an FTP site and sometimes the file will not be there how can I exit the PHP gracefully ? If there is not a file I get the below error message. ftp_get(): Requested action not taken. Message not found. Error downloading sample.txt if (ftp_get($ftp_conn, $local_file, $ftp_path.$server_file, FTP_ASCII)) { echo "Successfully written to $local_file."; } else { echo "Error downloading $server_file."; ftp_close($ftp_conn); exit; } ftp_close($ftp_conn);
  4. I update my code to use the implode and I changed my sql statement to test and I get the correct results. thanks $lines = []; $fp = fopen('sample.txt', 'r'); while (!feof($fp)) { $line = fgets($fp); $lines[substr($line, 69, 5)] = substr($line, 117, 2); } fclose($fp); $order=array_filter($lines,function($AA){ return $AA=='AA';} ); $key_string = implode(',', array_keys($order)); //print_r($key_string); $sql_update="select ompsalesorderid from .SalesOrders where ompsalesorderid in ($key_string)"; $connect = odbc_connect("1234"); $result = odbc_exec($connect, $sql_update); if(!$result){ exit("Error in SQL"); } while ($row = odbc_fetch_array($result)) { $orderid=$row['ompsalesorderid']; echo $orderid; } odbc_close($connect);
  5. I am pulling values from a text file and putting them in an associative array and then filtering them to get what I need. I would then like to use those key values in my MSSQL update statement. But I am not sure how to convey that to my MSSQL statement. How would I do that? <?php $lines = []; $fp = fopen('sample.txt', 'r'); while (!feof($fp)) { $line = fgets($fp); $lines[substr($line, 69, 5)] = substr($line, 117, 2); } fclose($fp); $order=array_filter($lines,function($AA){ return $AA=='AA';} ); $sql_update="update salesorders set ompOrderApproval= -1 where order_id in $orders_array_key_place_holder" $connect = odbc_connect("1234"); $update = odbc_exec($connect, $sql_update); odbc_close($connect); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.