<?php
    $dbc = new mysqli("localhost", "nobody", "", "test");
    $dbc->autocommit(false);
/*
    $dbc->query("delete from bugdemo");
    $dbc->commit();
*/
    /* insert a really long string */
    /* worked for up to 2184*10 chars, then breaks for larger */
    $longstring = "";
    for($i = 0; $i < 2185; ++$i)
        $longstring .= "0123456789";
    $name = "foo";

    print "length of longstring == ".strlen($longstring)."\n";
/*
    $insert = $dbc->prepare("insert into bugdemo(name, value) values(?, ?)");
    $insert->bind_param("ss", $name, $longstring);
    $insert->execute();
    $dbc->commit();
*/
    $select = $dbc->prepare("select value from bugdemo where name = ?");
    $select->bind_param("s", $name);
    $select->bind_result($value);
    $select->execute();
    $select->fetch();

    $length = strlen($value);
    print "length of value == $length\n";
    $errors = 0;

    if (strcmp($value, $longstring)) {
        print "The string values don't match\n";
	print "Original (last 20 bytes) ".substr($longstring,-20)."\n";
	print "From DB  (last 20 bytes) ".substr($value,-20)."\n";
    }
?>
