ads_prepare

Advantage PHP Extension

  Previous topic Next topic  

Prepares an SQL statement for execution.

Syntax

resource ads_prepare( resource connection_id,

string query )

Parameters

connection_id (I)

ID of a connection to the Advantage Database Server.

query (I)

The SQL statement to be prepared.

Remarks

Use ads_prepare when executing SQL statements containing parameters. To execute the SQL statement, call ads_execute with the result set identifier returned by ads_prepare. If the statement could not be prepared, False is returned.

Named and unnamed parameters are supported. Named parameters are represented with a string preceded by a colon. The "string" portion may contain the characters ‘0..9’, ‘A..Z’, ‘a..z’, or the underscore character (‘_’). Unnamed parameters are represented by a question mark (?).

Example

<?

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";

?>

See Also

ads_connect

ads_execute