|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-11-08 15:29 UTC] f dot engelhardt at 21torr dot com
Description:
------------
Inserting a data into a blob column only inserts some of the data, in most cases between 1 and 200 Bytes, but not allways the same and never all data (which is in this case about 2 mb). I also tried it with mysqli_stmt_send_long_data(), but that was not working either.
The table is as followes:
CREATE TABLE `dbfs_data_chunk` (
`fileid` smallint(5) unsigned NOT NULL,
`version` smallint(5) unsigned NOT NULL default '0',
`data` mediumblob,
PRIMARY KEY (`fileid`,`version`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
MySQL-Version: 5.0.15
If i do a base64_encode() it works, but this isn?t a solution, only a bad workaround, which is not acceptable.
I also tried MyISAM, the same result.
Reproduce code:
---------------
<?php
$GLOBALS['CONN'] = mysqli_connect(...);
$s = file_get_contents('/usr/portage/distfiles/vim-runtime-20050601.tar.bz2');
$one = 1;
$two = 2;
$q = 'INSERT INTO dbfs_data_chunk VALUES (?,?,?)';
$stmt = mysqli_stmt_init($GLOBALS['CONN']);
mysqli_stmt_prepare($stmt,$q);
mysqli_stmt_bind_param($stmt,'iib',$one,$two,$s);
//mysqli_stmt_send_long_data($stmt,2,$s);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
exit;
?>
Expected result:
----------------
Should insert the binary data into the table
Actual result:
--------------
only 1 to 200 Bytes get inserted.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 12:00:01 2025 UTC |
This Problem is very annoying, becouse i am using innodb tables with foreign key constraints, and if i use mysqli_stmt_send_long_data() for any of the fields, all the other arent NULL anymore. So my constraint fails! Example: <?php $GLOBALS['CONN'] = mysqli_connect(...); mysqli_select_db(..); $s = file_get_contents('/usr/portage/distfiles/vim-runtime-20050601.tar.bz2') ; $one = NULL; $two = NULL; $q = 'INSERT INTO dbfs_data_chunk VALUES (?,?,?)'; $stmt = mysqli_stmt_init($GLOBALS['CONN']); mysqli_stmt_prepare($stmt,$q); mysqli_stmt_bind_param($stmt,'iib',$one,$two,$s); //mysqli_stmt_send_long_data($stmt,2,$s); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); exit; ?> without mysqli_stmt_send_long_data() i have the problem as described, and with mysqli_stmt_send_long_data() on the blob field, mysql tells me, that the constraint gets violated! This can only happen, if the variables $one and $two are not NULL.Well, i allready tried this: <?php mysqli_connect(..); mysqli_select_db(..); $s = file_get_contents('/usr/portage/distfiles/vim-runtime-20050601.tar.bz2'); $one = 1; $two = 2; $q = 'INSERT INTO dbfs_data_chunk VALUES (?,?,?)'; $stmt = mysqli_stmt_init($GLOBALS['CONN']); mysqli_stmt_prepare($stmt,$q); mysqli_stmt_bind_param($stmt,'iis',$one,$two,$s); mysqli_stmt_execute($stmt); mysqli_stmt_close($stmt); exit; ?> Exaclty the same problem. Fix it. Kind Regards Florian EngelhardtZ_STRLEN_PP() macro does not use the strlen() function. It's a macro to access the real length from the zval** (PP). So, from what I see it should work correctly. PHP reads the file and is \0 aware so the length in the zval that represents the string should be ok. I have done a test and for me it seems to work ok. See the md5() hash of what's in the column. Just mysql cmdline client does not show the whole string but stops at the \0. Try with the function LENGTH() and it will work (shows 8 for me). mysql> create table blob_test (a mediumblob); Query OK, 0 rows affected (0.19 sec) ----------------------------------------------------- php -r ' $c=new mysqli("127.0.0.1", "root",""); var_dump($c); $s=$c->prepare("INSERT INTO test.blob_test VALUES(?)"); $v="aaaa\0bbb"; $s->bind_param("s",$v); var_dump($s->execute(), $s->execute());' ------------------------------------------------------- mysql> select md5("aaaa"), md5("aaaa\0bbb"), md5(a), a from blob_test\G *************************** 1. row *************************** md5("aaaa"): 74b87337454200d4d33f80c4663dc5e5 md5("aaaa\0bbb"): f04bbe8400c631e6bab90d30900ccc69 md5(a): f04bbe8400c631e6bab90d30900ccc69 a: aaaa *************************** 2. row *************************** md5("aaaa"): 74b87337454200d4d33f80c4663dc5e5 md5("aaaa\0bbb"): f04bbe8400c631e6bab90d30900ccc69 md5(a): f04bbe8400c631e6bab90d30900ccc69 a: aaaa 2 rows in set (0.00 sec)