ads_execute

Advantage PHP Extension

  Previous topic Next topic  

Executes a prepared SQL statement.

Syntax

resource ads_execute( resource result_id

[, array parameters_array]

[,array parameter_types_array] )

Parameters

result_id (I)

ID of a result set.

parameters_array (I)

Optional array of values to be bound to the parameters of an SQL statement.

parameters_type_array (I)

Optional array of types associated with the values to be bound to the parameters. Available options are: SQL_BINARY, SQL_CHAR, and SQL_WCHAR.

Remarks

ads_execute executes a statement that has been prepared by a previous call to ads_prepare. Use of this function is required when executing an SQL statement that contains parameters. Parameters in the parameters_array are substituted for placeholders in the order they appear in the SQL statement.

The values in the parameter_types_array are used to correctly pass the parameter data to the Advantage Database Server when working with binary or Unicode data. Set the type to SQL_BINARY for data that is binary, SQL_WCHAR for Unicode fields, and all other fields should use SQL_CHAR.

When executing a successful SELECT statement or EXECUTE statement with a result set, a result set identifier will be returned. This result set identifier can be used to retrieve values from the result set.

Examples

<?

echo "Connecting to Server<br>\n";

$rConn = ads_connect( "DataDirectory=\\\\server1\\share1\\data\\;ServerTypes=2", "", "" );

echo "Connected<br>\n";

 

echo "Preparing a statement with a parameter<br>\n";

$rStmt = ads_prepare( $rConn, "SELECT * FROM customers WHERE company LIKE ?" );

echo "Statement prepared<br>\n";

 

echo "Executing the statement. Notice the array of parameters<br>\n";

$aParams = array( 1 => 'A%' );

$rResult = ads_execute( $rStmt, $aParams );

echo "Execution was successful<br>\n";

 

echo "Retrieve the Company Name and Credit Limit<br>\n";

while ( ads_fetch_row( $rStmt ) )

{

$strCompanyName = ads_result( $rStmt, "COMPANY" );

$strCreditLimit = ads_result( $rStmt, "CREDIT_LIMIT" );

echo $strCompanyName . " can spend up to $" . $strCreditLimit . "<br>\n";

}

 

echo "Closing the connection<br>\n";

ads_close( $rConn );

echo "Disconnected<br>\n";

?>

 

An example of inserting binary data using parameters:

 

<?php

 

$rConn = ads_connect("DataDirectory=//server1/share1/data/;ServerTypes=2","", "");

echo "Connected<br>\n";

 

echo "Reading file into buffer<br>\n";

$infile = fopen ( "c:\data\picture.bmp", "rb");

if ($infile) //does the comp file exist?

{

$buf = "";

while (!feof($infile))

$buf .= fread ($infile, 1024);

$doc_data = $buf;

fclose ($infile);

}

 

 

echo "Performing the insert<br>\n";

echo "Preparing an insert statement with a blob and binary parameter<br>\n";

$rStmt = ads_prepare( $rConn, "INSERT INTO Employee ( EmpID, MugShot ) VALUES ( ?, ? )" );

echo "Statement prepared<br>\n";

 

$insertarray = array(1 => $doc_data);

 

$insertarray = array(1 => 69,

2 => $doc_data);

 

$typesarray = array( 1 => SQL_CHAR,

2 => SQL_BINARY );

 

echo "Executing the statement<br>\n";

$insertresult = ads_execute( $rStmt, $insertarray, $typesarray );

echo "The statement has been executed. <br>\n";

 

echo "Closing the connection<br>\n";

ads_close( $rConn );

echo "Disconnected<br>\n";

 

 

?>

 

See Also

ads_connect

ads_prepare

ads_do

ads_exec