php-general Digest 13 Dec 2011 20:33:42 -0000 Issue 7608

Topics (messages 315981 through 315990):

Re: Syntax problem PDO and bindvalue
        315981 by: Fatih P.
        315982 by: FeIn
        315983 by: Fatih P.

PHP 5.3.6 Dates
        315984 by: Floyd Resler
        315985 by: Ian
        315986 by: Matijn Woudt

Re: php-general Digest 9 Dec 2011 20:09:28 -0000 Issue 7604
        315987 by: David Savage
        315988 by: Daniel P. Brown
        315989 by: David Harkness

Split
        315990 by: Jack

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---


On 12/12/2011 01:49 PM, Stephen wrote:
So I am getting this SQL error:

Error selecting photographs: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''4'' at line 2

My code is:

function updatephotos($dbh, $x) {

echo $x['number'] . "<br />"; <<<<< this echo is 4

  $sql = "SELECT * FROM photographs WHERE
              photo_filename LIKE '%2%' LIMIT 0, :q;";

  $stmt = $dbh->prepare($sql);

  try {

        $stmt->bindValue( ':q', $x['number'], PDO::PARAM_INT );
        $stmt->execute();

      } catch (PDOException $e) {
            return 'Error selecting photographs: ' . $e->getMessage();
    }

while ( list( $id, $name, $alt, $caption) = $stmt->fetch(PDO::FETCH_NUM)) {
echo $name . "<br />";
        }


  return "test worked" ;
}

If I hard code the SQL as:

$sql = "SELECT * FROM photographs WHERE
              photo_filename LIKE '%2%' LIMIT 0, 4";

all works well.

Can anyone see what is wrong?

How can I see the prepared SQL statement before it is executed?

Thanks
Stephen


$x = $x['number'];

$stmt->bindValue( ':q', $x['number'], PDO::PARAM_INT );

i didnt dig deep down the problem [might be some C thing, pointer access or ...] but this solves it.

Fatih P.
http://blog.teknober.com

--- End Message ---
--- Begin Message ---
I don't think you're suppose to end your queries with a semicolon. Try:

$sql = "SELECT * FROM photographs WHERE
             photo_filename LIKE '%2%' LIMIT 0, :q";


On Mon, Dec 12, 2011 at 1:49 PM, Stephen <stephe...@rogers.com> wrote:

> So I am getting this SQL error:
>
> Error selecting photographs: SQLSTATE[42000]: Syntax error or access
> violation: 1064 You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use near
> ''4'' at line 2
>
> My code is:
>
> function updatephotos($dbh, $x) {
>
> echo $x['number'] . "<br />"; <<<<< this echo is 4
>
>  $sql = "SELECT * FROM photographs WHERE
>              photo_filename LIKE '%2%' LIMIT 0, :q;";
>
>  $stmt = $dbh->prepare($sql);
>
>  try {
>
>        $stmt->bindValue( ':q', $x['number'], PDO::PARAM_INT );
>        $stmt->execute();
>
>      } catch (PDOException $e) {
>            return 'Error selecting photographs: ' . $e->getMessage();
>    }
>
> while ( list( $id, $name, $alt, $caption) = $stmt->fetch(PDO::FETCH_NUM)) {
> echo $name . "<br />";
>        }
>
>
>  return "test worked" ;
> }
>
> If I hard code the SQL as:
>
> $sql = "SELECT * FROM photographs WHERE
>              photo_filename LIKE '%2%' LIMIT 0, 4";
>
> all works well.
>
> Can anyone see what is wrong?
>
> How can I see the prepared SQL statement before it is executed?
>
> Thanks
> Stephen
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Mon, Dec 12, 2011 at 4:22 PM, FeIn <aci...@gmail.com> wrote:

> I don't think you're suppose to end your queries with a semicolon. Try:
>

you can end your queries with semicolon in prepared statements.

How can I see the prepared SQL statement before it is executed?
try->  var_dump ($statement);

--- End Message ---
--- Begin Message ---
If this was already discussed I apologize for the duplicate question.  For some 
reason dates of 0000-00-00 get converted to 11/30/-0001 with the date function. 
 Is this be design or a bug?

Thanks!
Floyd


--- End Message ---
--- Begin Message ---
On 12/12/2011 16:56, Floyd Resler wrote:
> If this was already discussed I apologize for the duplicate question.  For 
> some reason dates of 0000-00-00 get converted to 11/30/-0001 with the date 
> function.  Is this be design or a bug?
> 
> Thanks!
> Floyd
> 
> 

Hi,

In the past I have noticed that zero used in date functions causes a
subtraction.  In this case it is probably working like this (all
speculation!)

Start with 1 Jan 0000

Take away 1 Month gives:

31 Nov -0001 (not valid though)

Take away 1 day

30 Nov -0001

I'm sure someone with more knowledge of the internals can explain this
better.

Regards

Ian
-- 





--- End Message ---
--- Begin Message ---
On Mon, Dec 12, 2011 at 5:56 PM, Floyd Resler <fres...@adex-intl.com> wrote:
> If this was already discussed I apologize for the duplicate question.  For 
> some reason dates of 0000-00-00 get converted to 11/30/-0001 with the date 
> function.  Is this be design or a bug?
>
> Thanks!
> Floyd
>

It might be related to timezones. There was a thread about a month ago
which might help you [1]. If it's not, then you might want to post
your code so we can take a closer look at it.

Cheers,

Matijn

[1] http://news.php.net/php.general/315699

--- End Message ---
--- Begin Message ---
I thought I posted this in the php.net web site under the "ksort" user notes, 
but I don't know if it would be approved to be placed in the web site.  
 
Would "ksort($sortarr,SORT_STRING)" on a 1 dimensional array with a key 
comprised of 
a person's name,
"-", and 
 time stamp
I..E. (key:  david savage-2011-12-12 14:43:00)
actually delete duplicate keys from the array, if there were two keys the same ?
Did not see anything regarding this in the user notes of "ksort" page in php.net
David
________________________________

From: php-general-digest-h...@lists.php.net 
[mailto:php-general-digest-h...@lists.php.net]
Sent: Fri 12/9/2011 2:09 PM
To: php-gene...@lists.php.net
Subject: php-general Digest 9 Dec 2011 20:09:28 -0000 Issue 7604




php-general Digest 9 Dec 2011 20:09:28 -0000 Issue 7604

Topics (messages 315962 through 315967):

Re: Think I found a PHP bug
        315962 by: Lester Caine

Question about performance between for iteration and extension function
        315963 by: Lin Yo-An
        315966 by: Matijn Woudt

Re: End of session clean-up
        315964 by: Andre Majorel

offline practice
        315965 by: saeed ahmed

PHP, PDO and MS-SQL ?
        315967 by: Andreas

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------



--- End Message ---
--- Begin Message ---
On Mon, Dec 12, 2011 at 16:06, David Savage <dsav...@cytelcom.com> wrote:
> I thought I posted this in the php.net web site under the "ksort" user notes, 
> but I don't know if it would be approved to be placed in the web site.
>
> Would "ksort($sortarr,SORT_STRING)" on a 1 dimensional array with a key 
> comprised of
> a person's name,
> "-", and
>  time stamp
> I..E. (key:  david savage-2011-12-12 14:43:00)
> actually delete duplicate keys from the array, if there were two keys the 
> same ?
> Did not see anything regarding this in the user notes of "ksort" page in 
> php.net

    If it's a question posted there as a user note, I would delete it.
 I put up a big sign on the page for posting user notes months ago,
complete with an XKCD strip, but somehow still, no one seems to notice
it (or read it, at least).

-- 
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/

--- End Message ---
--- Begin Message ---
On Mon, Dec 12, 2011 at 1:06 PM, David Savage <dsav...@cytelcom.com> wrote:

> Would "ksort($sortarr,SORT_STRING)" on a 1 dimensional array with a key
> comprised of
> a person's name,
> "-", and
>  time stamp
> I..E. (key:  david savage-2011-12-12 14:43:00)
> actually delete duplicate keys from the array, if there were two keys the
> same ?
>

Unless I'm missing something, you couldn't have two entries with the same
key in the array to begin with.

    $a = array();
    $a['david savage-2011-12-12 14:43:00'] = 1;
    $a['david savage-2011-12-12 14:43:00'] = 2;
    print_r($a);

    Array
    (
        [david savage-2011-12-12 14:43:00] => 2
    )

David

--- End Message ---
--- Begin Message ---
OK so I have seen enough errors about split, so I decided to update my code:

  return split("/", $sPath, $iMax);

 

I tried:

return preg_split("/", $sPath, $iMax);

return preg_split("/", $sPath, $iMax, PREG_SPLIT_DELIM_CAPTURE);

 

and a few other combinations, in the end always with errors. not sure I get
the additional aspect.

I do see ther error log it tells me no ending delimiter

 

Any help appreciated.

 

 

Thanks!

Jack

 


--- End Message ---

Reply via email to