Guest User

Untitled

a guest
Jul 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. CREATE TABLE `prob` (
  2. `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  3. `key` VARBINARY(4) NOT NULL,
  4. PRIMARY KEY (`id`)
  5. ) ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_general_ci;
  6. INSERT INTO `prob` ( `key` ) VALUES ( 0x1234 );
  7.  
  8. $key = pack( "H*", '01020304' );
  9. if( $stmt = $con->prepare("INSERT INTO prob VALUES ( DEFAULT, ? )") ) {
  10. $stmt->bind_param( "s", $key );
  11. $stmt->execute( );
  12. $stmt->close( );
  13. } else { $err = $con->error; echo "Err $err<br>"; }
  14.  
  15. if( $stmt = $con->prepare("SELECT id FROM prob WHERE key='?'") ) {
  16. if( !$stmt->bind_param( "s", $key ) ) {echo 'Err bind_param.<br>'; die( );}
  17. if( !$stmt->execute( ) ) {echo 'Err execute.<br>'; die( );}
  18. if( !$stmt->bind_result( $id ) ) {echo 'Err bind_result.<br>'; die( );}
  19. $rv = $stmt->fetch( );
  20. $stmt->close( );
  21. echo 'Result: '.print_r( $rv ).'<br>';
  22. } else { $err = $con->error; echo "Err $err<br>"; }
  23.  
  24. if($result = $con->query( "SELECT id FROM prob WHERE key=$key" )) {
  25. if( $count = $result->num_rows == 1 ) {
  26. $row = $result->fetch_row( );
  27. $rv = $row[0];
  28. $result->close( );
  29. }
  30. } else { $err = $con->error; echo "Err $err<br>"; }
Add Comment
Please, Sign In to add comment