Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This works for me:</p> <pre><code>DROP TABLE IF EXISTS `binary`; CREATE TABLE `binary`( id INT NOT NULL AUTO_INCREMENT, ba VARBINARY( 100 ), PRIMARY KEY(`id`) ) ENGINE=MYISAM; </code></pre> <p>and PHP code (using PDO):</p> <pre><code>&lt;?php $db = new PDO('mysql:dbname=test;host=localhost:4040','xxx','xxxx'); $_BIN=pack('I*', 3563547,6587568,5468456,6458568,4568568); $rs = $db-&gt;prepare("INSERT INTO `binary`(`ba`) VALUES(?)"); $rs-&gt;execute(array($_BIN)); </code></pre> <p><strong>UPDATE</strong></p> <p>See below the code based on your suggested one with named parameters:</p> <pre><code>&lt;?php $_SNB = 23; $_USR = "toto"; $_BIN = pack('I*', 24325, 2556456, 547577, 675746, 535646, 4564575, 575474, 4735); $db = new PDO('mysql:host=localhost:4040;dbname=test','xxxx','xxxx'); $db-&gt;exec('SET CHARACTER SET utf8'); $rs = $db-&gt;prepare("INSERT INTO `spw_license` (`serial_num`, `user`, `ba_struct`) VALUES(:serial_num, :username, :ba_struct)"); $rs-&gt;bindValue(':serial_num', $_SNB, PDO::PARAM_INT); $rs-&gt;bindValue(':username', $_USR); $rs-&gt;bindValue(':ba_struct', $_BIN, PDO::PARAM_LOB); try { if(!$rs-&gt;execute()) { var_dump($db-&gt;errorInfo()); } } catch(Exception $e) { echo 'got Exception: ' . $e-&gt;getMessage() . PHP_EOL; } </code></pre> <p>Here is how the table looks like after this is launched:</p> <pre><code>mysql&gt; select * from `spw_license`; +------------+------+----------------------------------+ | serial_num | user | ba_struct | +------------+------+----------------------------------+ | 23 | toto | ♣_ (☻' ∙ вO ^ _жE Є ⌂↕ | +------------+------+----------------------------------+ 1 row in set (0.00 sec) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload