alanl1 Posted June 26, 2013 Share Posted June 26, 2013 (edited) Hi professionals I have some code as follows /* The queries to be prepared for execution */ /*******************************************************/ $stmt = sqlsrv_query( $conn, $sql); $stmt1 = sqlsrv_query( $conn, $sql1); $droptable1 = sqlsrv_query( $conn, $droptable); $bulkinsert1 = sqlsrv_query( $conn, $bulkinsert); /*******************************************************/ /* Check the database connection is good */ /*******************************************************/ if( $conn === false) { die( print_r( sqlsrv_errors(), true) ); } /*******************************************************/ /* Prepare the drop table query. */ /*******************************************************/ if(!$droptable1 = sqlsrv_prepare( $conn, $droptable)) { echo "Could not prepare statement"; die( print_r( sqlsrv_errors(), true)); } /* Execute the drop table query. */ if( !sqlsrv_execute( $droptable1)) { echo "Error in executing statement.\n"; die( print_r( sqlsrv_errors(), true)); } /*******************************************************/ /* Prepare the Create table statement. */ /*******************************************************/ if(!$stmt = sqlsrv_prepare( $conn, $sql)) { echo "Could not prepare statement"; die( print_r( sqlsrv_errors(), true)); } /* Execute the Create table statement. */ if( !sqlsrv_execute( $stmt)) { echo "Error in executing statement.\n"; die( print_r( sqlsrv_errors(), true)); } /*******************************************************/ /* Prepare the BULK insert statement. */ /*******************************************************/ if(!$bulkinsert1 = sqlsrv_prepare( $conn, $bulkinsert)) { echo "Could not prepare statement"; die( print_r( sqlsrv_errors(), true)); } /* Execute the BULK insert statement. */ if( !sqlsrv_execute( $bulkinsert1)) { echo "Error in executing statement.\n"; die( print_r( sqlsrv_errors(), true)); } /*******************************************************/ /* Prepare the Cleansing data statement. */ /*******************************************************/ if(!$stmt1 = sqlsrv_prepare( $conn, $sql1)) { echo "Could not prepare statement"; die( print_r( sqlsrv_errors(), true)); } /* Execute the Cleansing data statement. */ if( !sqlsrv_execute( $stmt1)) { echo "Error in executing statement.\n"; die( print_r( sqlsrv_errors(), true)); } /******************************************************/ /* Release the Queries */ /*******************************************************/ sqlsrv_free_stmt( $droptable1); sqlsrv_free_stmt( $stmt); sqlsrv_free_stmt( $bulkinsert1); sqlsrv_free_stmt( $stmt1); /*******************************************************/ is there a better way to prepare, execute and realease them rather than repeating them one by one? thanks in advance Edited June 26, 2013 by alanl1 Quote Link to comment Share on other sites More sharing options...
Solution mac_gyver Posted June 26, 2013 Solution Share Posted June 26, 2013 store the query strings in an array. loop over the array to execute each query using one copy of the sqlsrv_prepare/sqlsrv_execute code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.