note 24549 deleted from ref.com by cmb
| From: | cmb@php.net | Date: | Sun, 30 Jun 2019 07:44:07 +0000 |
| Subject: | note 24549 deleted from ref.com by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-211413@lists.php.net to get a copy of this message | ||
Note Submitter: nospam at bol dot com dot br
----
This is a sample to make a parametrized query using ADO via COM, this sample was used with Foxpro
but will work's with most ADO complient databases. This was tested on IIS with WIN XP pro.
<?php
// Create the main connection
$dbc = new COM("ADODB.Connection") or die ("connection create fail");
$dbc->Provider = "MSDASQL";
$dbc->Open("FoxDatabase");
// Creates a temporary record set
$RSet = new COM("ADODB.Recordset");
// Create one ADO command
$cm = new COM("ADODB.Command");
$cm->Activeconnection = $dbc;
// the ? inside values will be the parameters $par01 and $par02
$cm->CommandText = "Insert Into testtable ( mycharfield,mymemofield) VALUES (?,?)" ;
$cm->Prepared = TRUE;
// Creates and append 2 parameters
$par01 = $cm->CreateParameter('ppar01',129,1,50,'ABCDEFGHIKL');
$cm->Parameters->Append($par01);
$par02 = $cm->CreateParameter('ppar01',129,1,50,'123456789012346789');
$cm->Parameters->Append($par02);
// Call 10 times the exec comand to show 10 different queries
for ($i = 1; $i <= 10; $i++) {
$par01->Value = 'Count '.$i;
$par02->Value = 'Passing here'.$i.' times';
$RSet = $cm->Execute;
}
$RSet = $dbc->Execute("select * from testtable");
while (!$RSet->EOF){
echo $RSet->fields["mycharfield"]->value.' ' ;
echo $RSet->fields["mymemofield"]->value ;
echo '<BR>';
$RSet->movenext();
}
$RSet->close;
$dbc->close;
$cm->close;
$RSet = null;
$dbc = null;
$cm = null;
?>