note
haukex
<blockquote><i>Anyway - LIKE is fail as well </i></blockquote>
<p>Sorry, but that is not an adequate problem description. Please see [id://174051] and [id://510718], and provide a [id://1177642], like the following. Note how it is exactly the code you posted, except that it works fine for me.</p>
<c>
use warnings;
use strict;
use feature 'say';
use DBI;
my $dbh = DBI->connect(
"DBI:mysql:database=testing;host=127.0.0.1", $ENV{USER},
'barfoo', { RaiseError => 1, AutoCommit => 1 });
$dbh->do('DROP TABLE IF EXISTS texts');
$dbh->do(<<'ENDSQL');
CREATE TABLE texts (
string VARCHAR(256)
);
ENDSQL
$dbh->do('INSERT INTO texts (string) VALUES ("/a/b/c");');
# ---
my $string = '/a/b/c';
my $req = qq{ SELECT * FROM `texts` WHERE `string`=?};
my $sth = $dbh->prepare($req);
my $row = $sth->execute($string);
say "row = $row";
# ---
my $sth2 = $dbh->prepare(
q{ SELECT * FROM texts WHERE string LIKE '%/a/b/c%' });
$sth2->execute;
say "row = $row";
</c>
<p>This prints <c>row = 1</c> twice, as expected.</p>
<p>This is how I spun up a fresh test MySQL instance. To change the server's port number, change the <c>-p3306:3306</c> to something like <c>-p13306:3306</c> in the <c>docker</c> command, add the argument <c>--port=13306</c> to the <c>mysql</c> command, and add the argument <c>;port=13306</c> to the DBI connection string in the Perl code.</p>
<pre>
$ docker run --rm --name testmysql -p3306:3306 -e MYSQL_ROOT_PASSWORD=foobar -d mysql:5
# wait a few seconds for it to start
$ echo "CREATE USER '$USER' IDENTIFIED BY 'barfoo'; CREATE DATABASE testing; GRANT ALL PRIVILEGES ON testing.* TO '$USER';" | mysql --protocol=TCP --user=root --password=foobar
# after testing:
$ docker stop testmysql
</pre>
<p><small><i>Several smaller edits to add more information.</i></small></p>
11123483
11123487