Skip to content

Instantly share code, notes, and snippets.

@pingpoli
Last active July 5, 2020 21:34
Show Gist options
  • Save pingpoli/52104ec9794174b12c3d9d593b66a598 to your computer and use it in GitHub Desktop.
Save pingpoli/52104ec9794174b12c3d9d593b66a598 to your computer and use it in GitHub Desktop.
<?php
$sql = "INSERT INTO table ( a , b , c ) VALUES ( ? , ? , ? )";
// prepared statement without the wrapper function
if ( $stmt = $mysql->prepare( $sql ) )
{
if ( $stmt->bind_param( "iis" , 1 , 2 , "string" ) )
{
if ( $stmt->execute() )
{
$stmt->close();
echo "success";
}
else
{
$stmt->close();
echo "execute error";
}
}
else
{
$stmt->close();
echo "bind_param error";
}
}
else
{
echo "prepare error";
}
// prepared statement with the wrapper function
if ( lmysql_execute( $mysql , $sql , "iis" , 1 , 2 , "string" ) )
{
echo "success";
}
else
{
echo "fail";
}
// normal query
if ( $mysql->query( "INSERT INTO table ( a , b , c ) VALUES ( 1 , 2 , 'string' )" ) )
{
echo "success";
}
else
{
echo "fail";
}
// select example
if ( $result = lmysql_select( $mysql , "SELECT * FROM table WHERE ID=?" , "i" , 123 ) )
{
while ( $row = $result->fetch_assoc() )
{
var_dump( $row );
}
}
else
{
echo "fail";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment