parameters not working under PDO

parameters not working under PDO

am 31.10.2007 19:43:48 von Chris Curvey

It's quite possible that I'm missing something obvious here. The
following code fragment does not return any rows, but if I take out the
parameters and replace them with hardcoded strings (enclosed in single
quotes), I get the right results.

I've scattered "print" statements throughout, and the query seems to get
past execute() OK, it's just not returning anything from the call to fetch()

Am I missing something obvious?

$stmt = $conn->prepare("select t.z from towns t
join counties c on t.county_z = c.z
where t.me = ?
and c.state_z = ?");
if ($stmt->execute($parts)) {
while ($row = $stmt->fetch()) {
$town_z = $row['z'];
}
} else {
print $stmt->errorCode();
print_r($stmt->errorInfo());
}

Thanks in advance!

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: parameters not working under PDO

am 31.10.2007 19:58:28 von Goltsios Theodore

--------------020304090707010405090003
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit



O/H Chris Curvey ??????:
> It's quite possible that I'm missing something obvious here. The
> following code fragment does not return any rows, but if I take out
> the parameters and replace them with hardcoded strings (enclosed in
> single quotes), I get the right results.
>
> I've scattered "print" statements throughout, and the query seems to
> get past execute() OK, it's just not returning anything from the call
> to fetch()
>
> Am I missing something obvious?
>
> $stmt = $conn->prepare("select t.z from towns t
> join counties c on t.county_z = c.z
> where t.me = ?
> and c.state_z = ?");
> if ($stmt->execute($parts)) {
> while ($row = $stmt->fetch()) {
> $town_z = $row['z'];
> }
What is $parts doing ?? You just need execute() and I suppose although
not posted that you did construct the object like:
$conn| = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

|A good choice is to tell fetch a way to retrieve your data like this:
$town_z = $stmt->fetch(PDO::FETCH_ASSOC);
although I think that it will get both result sets in case you don't define.
> } else {
> print $stmt->errorCode();
> print_r($stmt->errorInfo());
> }
>
> Thanks in advance!
>
A better way debug that I know is using exceptions like:
try {
$sth = $conn->query($query);
$rs = $sth->fetch();
} catch (Exception $e) {
print "failed :".$e->getMessage();
}

You can use try {} with almost everything so give it a "try" :-) .

Send us some feed back or post full source if you keep having trouble.

--
Thodoris


--------------020304090707010405090003--

Trouble with Text Area

am 31.10.2007 20:04:44 von Stephen Sunderlin

When I put his line outside of the php tags I get the correct size:



When I put this line inside the php tags the size comes out about 2 rows by
10 columns regardless of the value of rows and cols.

Any ideas on how to format this would be greatly appreciated. The mySQL db
column TYPE I am calling is Blob not null.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: parameters not working under PDO

am 31.10.2007 20:06:57 von Michael Preslar

Check $parts.. print_r($parts) and make sure its 1) an array 2)
contains 2 values

On 10/31/07, Chris Curvey wrote:
> It's quite possible that I'm missing something obvious here. The
> following code fragment does not return any rows, but if I take out the
> parameters and replace them with hardcoded strings (enclosed in single
> quotes), I get the right results.
>
> I've scattered "print" statements throughout, and the query seems to get
> past execute() OK, it's just not returning anything from the call to fetch()
>
> Am I missing something obvious?
>
> $stmt = $conn->prepare("select t.z from towns t
> join counties c on t.county_z = c.z
> where t.me = ?
> and c.state_z = ?");
> if ($stmt->execute($parts)) {
> while ($row = $stmt->fetch()) {
> $town_z = $row['z'];
> }
> } else {
> print $stmt->errorCode();
> print_r($stmt->errorInfo());
> }
>
> Thanks in advance!
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: parameters not working under PDO

am 31.10.2007 20:16:17 von Chris Curvey

good thing to check...it seems to be OK.

Array ( [0] => montclair [1] => nj )

Michael Preslar wrote:
> Check $parts.. print_r($parts) and make sure its 1) an array 2)
> contains 2 values
>
> On 10/31/07, Chris Curvey wrote:
>> It's quite possible that I'm missing something obvious here. The
>> following code fragment does not return any rows, but if I take out the
>> parameters and replace them with hardcoded strings (enclosed in single
>> quotes), I get the right results.
>>
>> I've scattered "print" statements throughout, and the query seems to get
>> past execute() OK, it's just not returning anything from the call to fetch()
>>
>> Am I missing something obvious?
>>
>> $stmt = $conn->prepare("select t.z from towns t
>> join counties c on t.county_z = c.z
>> where t.me = ?
>> and c.state_z = ?");
>> if ($stmt->execute($parts)) {
>> while ($row = $stmt->fetch()) {
>> $town_z = $row['z'];
>> }
>> } else {
>> print $stmt->errorCode();
>> print_r($stmt->errorInfo());
>> }
>>
>> Thanks in advance!
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Trouble with Text Area

am 01.11.2007 00:14:50 von Stut

Stephen Sunderlin wrote:
> When I put his line outside of the php tags I get the correct size:
>



That's not how you specify the value of a textarea. It should be between
the tags like so...



And I'm assuming that $String has already had htmlentities run on it.

> When I put this line inside the php tags the size comes out about 2 rows by
> 10 columns regardless of the value of rows and cols.

Check the source of the page being created. I'm guessing $String
contains a single quote and then a sequence of characters that is
causing this behaviour.

> Any ideas on how to format this would be greatly appreciated. The mySQL db
> column TYPE I am calling is Blob not null.

-Stut

--
http://stut.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: parameters not working under PDO

am 01.11.2007 16:31:47 von Chris Curvey

Ah, but the *contents* of the array are not what I thought they
were...there was a leading space in "nj". Which brings me to something
I've been wondering...is there a way to get the statement object to tell
me EXACTLY what was sent to the database engine?



Chris Curvey wrote:
> good thing to check...it seems to be OK.
>
> Array ( [0] => montclair [1] => nj )
>
> Michael Preslar wrote:
>> Check $parts.. print_r($parts) and make sure its 1) an array 2)
>> contains 2 values
>>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php