Anyway - LIKE is fail as well
Sorry, but that is not an adequate problem description. Please see How do I post a question effectively? and I know what I mean. Why don't you?, and provide a Short, Self-Contained, Correct Example, like the following. Note how it is exactly the code you posted, except that it works fine for me.
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";
This prints row = 1 twice, as expected.
This is how I spun up a fresh test MySQL instance. To change the server's port number, change the -p3306:3306 to something like -p13306:3306 in the docker command, add the argument --port=13306 to the mysql command, and add the argument ;port=13306 to the DBI connection string in the Perl code.
$ 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
Several smaller edits to add more information.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|