<?xml version="1.0" encoding="windows-1252"?>
<node id="1008249" title="Re: DBI Substring index query and passing value" created="2012-12-11 04:29:04" updated="2012-12-11 04:29:04">
<type id="11">
note</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
&lt;p&gt;And what does your query produce when run straight against the database with an SQL command prompt?&lt;/p&gt;

&lt;p&gt;How many records are there in the database that begin with &lt;c&gt;'$name'&lt;/c&gt;? Does &lt;c&gt;fetchrow_array&lt;/c&gt; return false? (If so, your resultset is zero rows.)&lt;/p&gt;

&lt;p&gt;Also, I'm quite confused by the query. Do you have fields that are named &lt;c&gt;$$$&lt;/c&gt;? (Double quotes are meant to quote table and field names in the SQL dialects I'm familiar with.)&lt;/p&gt;

&lt;p&gt;Perhaps you mean:&lt;/p&gt;

&lt;code&gt;
my $sql = sprintf("... where CustomField = ? and Name like %s", $dbh-&gt;quote($name . '%'));
$agent1 = $dbh-&gt;prepare($sql) || die $DBI::errstr;

$Agent1-&gt;execute(291)  || die $DBI::errstr ;

( $phone_no,$mail )= $Agent1-&gt;fetchrow_array or die "no results :(";
&lt;/code&gt;

&lt;p&gt;May I recommend you put RaiseError into your connection string? Less explicit dying.&lt;/p&gt;</field>
<field name="root_node">
1008099</field>
<field name="parent_node">
1008099</field>
<field name="reputation">
2</field>
</data>
</node>
