Created
July 7, 2020 16:00
-
-
Save pingpoli/09be50fbf5037aa1707d181b85df1394 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function lmysql_execute( $mysql , $sql , $types , ...$params ) | |
{ | |
if ( !( $stmt = $mysql->prepare( $sql ) ) ) | |
{ | |
error_log( "LMYSQL > prepare , errno: ".$mysql->errno.", error: ".$mysql->error ); | |
return false; | |
} | |
if ( strlen( $types ) > 0 ) | |
{ | |
// mysqli_stmt->bind_param requires references, therefore the array passed to call_user_func_array also needs to contain references | |
$bindParamArray = array(); | |
$bindParamArray[] = &$types; | |
for ( $i = 0 ; $i < strlen( $types ) ; ++$i ) $bindParamArray[] = &$params[$i]; | |
if ( !( call_user_func_array( array( $stmt , 'bind_param' ) , $bindParamArray ) ) ) | |
{ | |
$stmt->close(); | |
error_log( "LMYSQL > call_user_func_array , errno: ".$mysql->errno.", error: ".$mysql->error ); | |
return false; | |
} | |
} | |
if ( !( $stmt->execute() ) ) | |
{ | |
$stmt->close(); | |
error_log( "LMYSQL > execute , errno: ".$mysql->errno.", error: ".$mysql->error ); | |
return false; | |
} | |
$stmt->close(); | |
return true; | |
} | |
function lmysql_select( $mysql , $sql , $types , ...$params ) | |
{ | |
if ( !( $stmt = $mysql->prepare( $sql ) ) ) | |
{ | |
error_log( "LMYSQL > errno: ".$mysql->errno.", error: ".$mysql->error ); | |
return false; | |
} | |
if ( strlen( $types ) > 0 ) | |
{ | |
// mysqli_stmt->bind_param requires references, therefore the array passed to call_user_func_array also needs to contain references | |
$bindParamArray = array(); | |
$bindParamArray[] = &$types; | |
for ( $i = 0 ; $i < strlen( $types ) ; ++$i ) $bindParamArray[] = &$params[$i]; | |
if ( !( call_user_func_array( array( $stmt , 'bind_param' ) , $bindParamArray ) ) ) | |
{ | |
$stmt->close(); | |
error_log( "LMYSQL > errno: ".$mysql->errno.", error: ".$mysql->error ); | |
return false; | |
} | |
} | |
if ( !( $stmt->execute() ) ) | |
{ | |
$stmt->close(); | |
error_log( "LMYSQL > errno: ".$mysql->errno.", error: ".$mysql->error ); | |
return false; | |
} | |
if ( !( $result = $stmt->get_result() ) ) | |
{ | |
$stmt->close(); | |
error_log( "LMYSQL > errno: ".$mysql->errno.", error: ".$mysql->error ); | |
return false; | |
} | |
$stmt->close(); | |
return $result; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment