Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.


In reply to Re^3: DBI search for forward slash by haukex
in thread DBI search for forward slash by luxs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2021-05-19 03:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (186 votes). Check out past polls.

    Notices?