Re: possible variable declaration error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Mar 25, 2011 at 8:23 AM, <james@xxxxxxxxxxxxxxx> wrote:

> Correct me if I wrong, but you're declaring $id AFTER binding the SQL
> parameter, therefore your :id isn't being bound to anything, hence the empty
> returned array.
>
> I think:
> $d_series_fetch = $db->prepare("SELECT * FROM defaultseries WHERE publisher
> >> :id");
> $id = 'DC Comics';
> $d_series_fetch->bindParam(':id',$id);
>
> *should* work.
>
> No that doesn't work either, I have a few INSERT statements using prepared
statements like so

$defaultseries = 'Batman';  //declare the php variable
$publisher = 'DC Comics';  //declare the php variable
$d_series->execute();  //execute the prepared statement

 and they work just fine.  Not entirely sure yet why, I am just starting to
really get into PDO's.


>---- Original Message ----
> >From: matty jones <urlugal@xxxxxxxxx>
> >To: php-general@xxxxxxxxxxxxx
> >Sent: Fri, Mar 25, 2011, 8:19 AM
> >Subject:  possible variable declaration error
> >
> >I get the following error " PHP Notice:  Undefined index: publisher in
> >/var/www/testfunctions.php on line 65" and I have narrowed it down to what
> I
> >*think* is a variable not being declared.  Here is the code.
> >
> >
> >//this will fetch the data from a table
> >$d_series_fetch = $db->prepare("SELECT * FROM defaultseries WHERE
> publisher
> >= :id");
> >$d_series_fetch ->bindParam(':id', $id);
> >$id = 'DC Comics';
> >
> >
> >if ($d_series_fetch ->execute(array($_GET['publisher']))) {
> >while ($row = $d_series_fetch -> fetch()) {
> >print_r($row);
> >}
> >}
> >
> >I have prepared statements to open a connection and insert data and they
> >work fine if I comment the preceding block out so I am fairly certain the
> >problem is in there somewhere.  I am using the latest version of PHP and
> am
> >running Postgres8.4 as my db.  If I use the isset() function and add an
> echo
> >(code below) I get no errors but the query still  doesn't work so again I
> am
> >fairly certain that I am forgetting to declare something somewhere.
> >
> >//this will fetch the data from a table
> >$d_series_fetch = $db->prepare("SELECT * FROM defaultseries WHERE
> publisher
> >= :id");
> >$d_series_fetch ->bindParam(':id', $id);
> >$id = 'DC Comics';
> >
> >$publisher = '';
> >
> >if (isset($_GET['publisher']))
> >{
> >
> >if ($d_series_fetch ->execute(array($_GET['publisher']))) {
> >while ($row = $d_series_fetch -> fetch()) {
> >print_r($row);
> >
> >}
> >}
> >}
> >
> >else {echo"this didn't work";}
> >
> >$dbh = null;  //close the database connection by setting the PDO object to
> >NULL
> >   }
> >
> >I am fairly new to PHP and have very little idea on PDO's so this is most
> >likely a simple error(s) I know.
> >Thank
> >
> >Matt
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux