467,923 Members | 1,260 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

Strange issue with odbc_execute()

<?php

global $TABLE_GL_DATA;
global $connect;

$PREPARED_SQL = odbc_prepare($connect, "INSERT INTO $TABLE_GL_DATA
VALUES (?,?,?,?,?,?,?)");

function Generate_GL_Data()
{

global $connect;
global $TABLE_WORKING;

$query = "SELECT INVOICE, TRACKING, AMOUNT, REFERENCE, SNAME, SADD1,
SADD2, SADD3, SCITY, SSTATE, SZIP, RNAME, RADD1, RADD2, RADD3, "
."RCITY, RSTATE, RZIP FROM $TABLE_WORKING WHERE BATCHNUM = " .
$_GET["BATCH_NUMBER"];
$result = odbc_exec($connect, $query);

while (odbc_fetch_row($result)) {
Parse_Results($result);
}
odbc_commit($connect);

}

Function Parse_Results($result)
{
$INVOICE = odbc_result($result, "INVOICE");
$TRACKING = odbc_result($result, "TRACKING");

$AMOUNT = odbc_result($result, "AMOUNT");
$REFERNECES = odbc_result($result, "REFERENCE");

$SZIP = odbc_result($result, "SZIP");
$RZIP = odbc_result($result, "RZIP");
// First attempt to take any cost centers from the reference data and
use those
if ( Generate_From_ProfitCenters($REFERNECES, $INVOICE, $TRACKING,
$AMOUNT) )
return;

// Now check for order numbers in the reference field and if they
exist obtain GJ data
if (Generate_From_Orders($REFERNECES, $SZIP) )
return;

// Now check for RMA numbers in the reference field and if they exist
obtain the GJ data
if ( Generate_From_RMA($REFERNECES, $RZIP) )
return;

// For all others check if they are known Vendors (ie they exist in
the Vendor Master file)
if ( Generate_From_Known_Vendor($REFERNECES) )
return;

//Generate_Defaults($INVOICE, $TRACKING, $AMOUNT);
//return;
global $PREPARED_SQL;

// default case where were are unable to figure out what this is
refering to
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING",
"0000000000", "00000000", $AMOUNT, "U");
print_r($myarray);
$result = odbc_execute($PREPARED_SQL, $myarray );
}

function Generate_Defaults($INVOICE, $TRACKING, $AMOUNT)
{
global $PREPARED_SQL;

// default case where were are unable to figure out what this is
refering to
$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING",
"0000000000", "00000000", $AMOUNT, "U");
print_r($myarray);
$result = odbc_execute($PREPARED_SQL, $myarray );
}
Function Generate_From_ProfitCenters($REFERENCES, $INVOICE, $TRACKING,
$AMOUNT)
{
global $PREPARED_SQL;

/** Regular expression to find the following
Starts with the number 1 with and contains a total of 10 digits
OR Starts with the number 1 and has the format of 1### #### ##
OR Starts with the number 1 and has the format of 1###.####.##
*/
$reg_exp = "/1\\d\\d\\d\\d\\d\\d\\d\\d\\d|1\\d\\d\\d \\d\\d\\d\\d
\\d\\d|1\\d\\d\\d\\.\\d\\d\\d\\d\\.\\d\\d/";

preg_match_all($reg_exp, $REFERENCES, $results);

$c = sizeof($results[0]);
$rand_num = rand(0, $c-1);

echo "<BR> $TRACKING $REFERENCES <BR>";
for ($i = 0; $i < $c; $i++) {
// Remove any instances of periods or spaces
$results[0][$i] = trim(str_replace(" ", "", $results[0][$i]));
$results[0][$i] = trim(str_replace(".", "", $results[0][$i]));

// We round down all partials because we'll add the remainder penny
to a random one
$partial_amount = floor($AMOUNT / $c * 100) / 100;

// Check if we're on the last found profit center AND the TOTAL
amount / number of profit centers doesn't divide evenly
// If so we have to tack on the remainder to a random portion
if ($i == $rand_num && ($AMOUNT / $c) != $partial_amount) {
$partial_amount = $AMOUNT - ($partial_amount * ($c - 1));
}

if (strpos($REFERENCES, "<p id='status'
style='display:none'>OUTGOING<p>") !== false)
$ACCOUNT = "50050000";
else
$ACCOUNT = "50106000";

$myarray = array($_GET['BATCH_NUMBER'], "$INVOICE", "$TRACKING",
"{$results[0][$i]}", "$ACCOUNT", $partial_amount, "U");
//print_r($myarray);
$result = odbc_execute($PREPARED_SQL, $myarray );
}

if ($c > 0) // Let the application know if we found any ProfitCenters
return true;
else
return false;
}
Originally I had the code from function Generate_Defaults(..) in
Parse_Results but I was getting a very strange error message

Warning: odbc_execute() [function.odbc-execute]: SQL error:
[IBM][Client Access Express ODBC Driver (32-bit)]Wrong number of
parameters., SQL state 07001 in SQLExecute in
C:\Inetpub\Accounting\WebSys\Accounts_Payable\Frei ght_EDI\Generate_GL_Data.php
on line 110

If I comment out the code (like it is above) and use the function
Generate_Defaults(..) I don't get this error message.

Now if I do the reverse (leave the default in Parse_Results() ) and
comment out Generate_From_ProfitCenters() it works...

It almost seems like there is an issue with scope and my variable
$PREPARED_SQL

Any ideas?

Apr 6 '06 #1
  • viewed: 1199
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by Neil Ginsberg | last post: by
3 posts views Thread by Sebastian C. | last post: by
2 posts views Thread by Joneleth | last post: by
2 posts views Thread by BinaryMonk | last post: by
3 posts views Thread by Max Vit | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.