Hi all
I need to read data from ODBC source, substring the once coloum then input the data into a Mysql Data Base
I have been able to read the data and get it substringed, the problem I am Having is getting it data into the MySQL data base.
Below is the code, if I uncomment the out "display the ODBC Result" It displays the correct result.
// open the odbc date Base
$conn = odbc_connect('bop','','')
or die ("Sorry - Could not Connect to odbc");
// Select Stock number and the Period
$sql="SELECT
STOCKNO,
PERIOD01
FROM
stockloc
WHERE
TYPE = 'N'";
$rs=odbc_exec($conn,$sql);
if (!$rs)
{exit("Error in SQL");}
while (odbc_fetch_row($rs))
{
$STOCKNO=odbc_result($rs,"STOCKNO");
$PERIOD1=odbc_result($rs,"PERIOD01");
$n00 = substr($PERIOD1,0,10);
$n01 = substr($PERIOD1,10,10);
$n02 = substr($PERIOD1,20,10);
$n02 = substr($PERIOD1,20,10);
$n03 = substr($PERIOD1,20,10);
$n04 = substr($PERIOD1,20,10);
$n05 = substr($PERIOD1,20,10);
$n06 = substr($PERIOD1,20,10);
$n07 = substr($PERIOD1,20,10);
$n08 = substr($PERIOD1,20,10);
$n09 = substr($PERIOD1,20,10);
$n10 = substr($PERIOD1,20,10);
$n11 = substr($PERIOD1,20,10);
$n12 = substr($PERIOD1,20,10);
$n13 = substr($PERIOD1,20,10);
$n14 = substr($PERIOD1,20,10);
$n15 = substr($PERIOD1,20,10);
$n16 = substr($PERIOD1,20,10);
$n17 = substr($PERIOD1,20,10);
$n18 = substr($PERIOD1,20,10);
$n19 = substr($PERIOD1,20,10);
$n20 = substr($PERIOD1,20,10);
// display the ODBC Result
// echo "<table><tr>";
// echo "<tr><td>$STOCKNO</td>";
//echo "<td>$PERIOD1</td>";
// echo "<td>$n00</td>";
// echo "<td>$n01</td>";
// echo "<td>$n02</td>";
// echo "</tr>";
}
odbc_close($conn);
//echo "</table>";
// open the mysqldate Base
$conn = mysql_connect( "localhost", "*", "*" )
or die ("Sorry - Could not Connect to MySQL");
$rs = mysql_select_db("bopfincon", $conn)
or die ("Sorry - Could not Connect to Database");
//insert normal stock into data base
$sql_stock_add="insert into stocklocmarch2007 (
STOCKNO,
n00,
n01,
n02,
n03,
n04,
n05,
n06,
n07,
n08,
n09,
n010,
n011,
n012,
n013,
n014,
n015,
n016,
n017,
n018,
n019,
n020
)
values (
'$STOCKNO',
'$00',
'$01',
'$02',
'$03',
'$04',
'$05',
'$06',
'$07',
'$08',
'$09',
'$010',
'$011',
'$012',
'$013',
'$014',
'$015',
'$016',
'$017',
'$018',
'$019',
'$020',
)";
$result = mysql_query($sql_stock_add, $conn);
# echo($sql_price_add);
if ($result)
{
$ia++;
set_time_limit(600);
}
echo("There were $ia stock items added");
I dont get any error messages, just no data is inserted into the database
Where am I going wrong
Thanks
Martin