php-general Digest 21 Jul 2009 17:46:50 -0000 Issue 6242

Topics (messages 295617 through 295636):

Re: running php script as a user?
        295617 by: Maximiliano Churichi

Re: PHP and FoxPro
        295618 by: Floyd Resler

Traffic throttling
        295619 by: Michelle Konzack
        295620 by: Stuart
        295621 by: דניאל דנון
        295622 by: Michelle Konzack

Re: putting variables in a variable
        295623 by: Mark Kelly

Search Query on two tables not working
        295624 by: Miller, Terion
        295625 by: Andrew Ballard
        295626 by: Dan Shirah
        295627 by: Miller, Terion
        295628 by: Miller, Terion
        295629 by: Miller, Terion
        295630 by: Dan Shirah
        295631 by: Miller, Terion
        295632 by: Ashley Sheridan
        295633 by: Andrew Ballard
        295634 by: Ashley Sheridan
        295635 by: Ashley Sheridan

Converting SQL Dialects
        295636 by: Matt Neimeyer

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 ---
sudo -u user command

2009/7/15 Adam Williams <awill...@mdah.state.ms.us>:
> I have a page where a user authenticates, fills in some information in an
> HTML form, and then when clicking on the submit button, will need to execute
> a php schell script as that user to write some data to their /home/username
> directory.  Since apache web server runs as the user nobody, how will I have
> that script execute as that user so that it can write data to their home
> directory?
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



-- 
Maximiliano Churichi
<mchuri...@gmail.com>

--- End Message ---
--- Begin Message ---
Matt,
Thanks for the information. I'll look into using ODBTP. I noticed you mentioned the problem with memos. I currently have that problem with the set up we're using and it is a pain!

Thanks!
Floyd

On Jul 20, 2009, at 3:22 PM, Matt Neimeyer wrote:

We currently use the Easysoft ODBC Bridge to connect to a remote FoxPro database. The problem is that the bridge, after a while, starts consuming a ton of system resources and we have to reboot the machine. Afterwards, it can take upwards to two hours before everything is running quickly again. We need another solution. Does anyone know of a any other way to connect
to a remote FoxPro database (or any ODBC source that isn't a database
server)?

We've had a LOT a luck using ODBTP. Which can be found at
http://odbtp.sourceforge.net

Here's the rough outline...

1. Install Visual FoxPro odbc driver (or whatever drivers you want) on
a Windows machine.
2. Install the ODBTP Server on the windows machine
3. Install a PHP module in your php. (Common ones included in the download)
4. Once you connect the functions are ALMOST exactly the same in usage
as the mysql_xyz functions.

A couple gotchas:

1. If you need to compile the PHP ODBTP module from source on x64 (OS
X Leopard at least) it can be a pain.
2. The VFP 6.0 ODBC driver (not sure about higher versions) does not
allow more than 250 odd characters to be inserted at a single time so
memo's can be a PAIN.
3. It does require a port be opened on the Windows machine's
firewall... (Uses TCP/IP for communication)
4. By default the ODBTP server can use up to 32 threads. The VFP ODBC
driver is by nature single threaded. We've never had a problem with
that directly but I assume it is what causes threads to slowly hang
and disappear... eventually a message comes up "Unable to create
thread". At that point you simply need to restart the ODBTP service in
the Windows Services Control Panel. The bigger the tables and the more
heavily used it is the more often this will happen.

Other than that... Works like a charm. Looking forward, once you bite
the bullet and convert to MySQL (at least for us) you can almost
change odbtp_ to mysql_ and be up and running. (Assuming you limit
yourself to "pure" SQL and not invoke VFP functions.)

Matt



--- End Message ---
--- Begin Message ---
Hello,

since I have not the file store in my webspace  for  security  reason,  I
use a php5 script to push it out.  It even support "resumeing".

some times ago, there was someone who told me to send out the  files  in
chunks of, e.g. 1 kByte, which let me know to count the REAL  traffic  a
client produce...

OK, now the script works perfectly and I am able to  delay  the  sending
between two chunks, but what I need is a milisecond timer, because 1s is
definitively to long.

Is there something in php5 I can use?

Thanks, Greetings and nice Day/Evening
    Michelle Konzack
    Systemadministrator
    Tamay Dogan Network
    Debian GNU/Linux Consultant

-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
<http://www.tamay-dogan.net/>                 Michelle Konzack
<http://www.can4linux.org/>                   c/o Vertriebsp. KabelBW
<http://www.flexray4linux.org/>               Blumenstrasse 2
Jabber linux4miche...@jabber.ccc.de           77694 Kehl/Germany
IRC #Debian (irc.icq.com)                     Tel. DE: +49 177 9351947
ICQ #328449886                                Tel. FR: +33  6  61925193

Attachment: signature.pgp
Description: Digital signature


--- End Message ---
--- Begin Message ---
2009/7/21 Michelle Konzack <linux4miche...@tamay-dogan.net>:
> since I have not the file store in my webspace  for  security  reason,  I
> use a php5 script to push it out.  It even support "resumeing".
>
> some times ago, there was someone who told me to send out the  files  in
> chunks of, e.g. 1 kByte, which let me know to count the REAL  traffic  a
> client produce...
>
> OK, now the script works perfectly and I am able to  delay  the  sending
> between two chunks, but what I need is a milisecond timer, because 1s is
> definitively to long.
>
> Is there something in php5 I can use?

http://php.net/usleep

-Stuart

-- 
http://stut.net/

--- End Message ---
--- Begin Message ---
I am not sure I understood you, But...
Use microtime(true/false) to get the time,
And usleep to sleep milliseconds

On Tue, Jul 21, 2009 at 6:31 PM, Michelle Konzack <
linux4miche...@tamay-dogan.net> wrote:

> Hello,
>
> since I have not the file store in my webspace  for  security  reason,  I
> use a php5 script to push it out.  It even support "resumeing".
>
> some times ago, there was someone who told me to send out the  files  in
> chunks of, e.g. 1 kByte, which let me know to count the REAL  traffic  a
> client produce...
>
> OK, now the script works perfectly and I am able to  delay  the  sending
> between two chunks, but what I need is a milisecond timer, because 1s is
> definitively to long.
>
> Is there something in php5 I can use?
>
> Thanks, Greetings and nice Day/Evening
>    Michelle Konzack
>    Systemadministrator
>    Tamay Dogan Network
>    Debian GNU/Linux Consultant
>
> --
> Linux-User #280138 with the Linux Counter, http://counter.li.org/
> ##################### Debian GNU/Linux Consultant #####################
> <http://www.tamay-dogan.net/>                 Michelle Konzack
> <http://www.can4linux.org/>                   c/o Vertriebsp. KabelBW
> <http://www.flexray4linux.org/>               Blumenstrasse 2
> Jabber linux4miche...@jabber.ccc.de           77694 Kehl/Germany
> IRC #Debian (irc.icq.com)                     Tel. DE: +49 177 9351947
> ICQ #328449886                                Tel. FR: +33  6  61925193
>



-- 
Use ROT26 for best security

--- End Message ---
--- Begin Message ---
Hello Stuart,

Am 2009-07-21 16:39:30, schrieb Stuart:
> http://php.net/usleep

Thank you, that it was.

Greetings and nice Day/Evening
    Michelle Konzack
    Systemadministrator
    Tamay Dogan Network
    Debian GNU/Linux Consultant

-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
<http://www.tamay-dogan.net/>                 Michelle Konzack
<http://www.can4linux.org/>                   c/o Vertriebsp. KabelBW
<http://www.flexray4linux.org/>               Blumenstrasse 2
Jabber linux4miche...@jabber.ccc.de           77694 Kehl/Germany
IRC #Debian (irc.icq.com)                     Tel. DE: +49 177 9351947
ICQ #328449886                                Tel. FR: +33  6  61925193

Attachment: signature.pgp
Description: Digital signature


--- End Message ---
--- Begin Message ---
Ross,

If I understand correctly what you want to do, you're almost there...

You need:

$myimage1 = "image1.jpg";
$myimage2 = "image2.jpg";
$myimage3 = "image3.jpg";

$body .="
<table>
  <tr>
    <td><img src=\"$myimage1\"></td>
  </tr>
  <tr>
    <td><img src=\"$myimage2\"></td>
  </tr>
  <tr>
    <td><img src=\"$myimage3\"></td>
  </tr>
</table>
";

Cheers,

Mark


--- End Message ---
--- Begin Message ---
Why isn't this working for searching?

   // Run query on submitted values. Store results in $SESSION and redirect to 
restaurants.php        $sql = "SELECT name, address, inDate, inType, notes, 
critical, cviolations, noncritical FROM restaurants, inspections WHERE 
restaurants.name <> '' AND restaurant.ID = inspection.ID";    if ($searchName)  
  {     $sql .= "AND restaurants.name LIKE '%". mysql_real_escape_string($name) 
."%' ";        if(count($name2) == 1)    {        $sql .= "AND restaurants.name 
LIKE '%". mysql_real_escape_string($name2[1]) ."%' ";    }    else    {        
foreach($name2 as $namePart)        {        $sql .= "AND restaurants.name LIKE 
'%". mysql_real_escape_string($namePart) ."%' ";        }    }    }    if 
($searchAddress) {        $sql .= "AND restaurants.address LIKE '%". 
mysql_real_escape_string($address) ."%' ";    }               $sql .= "ORDER BY 
restaurants.name;";                $result = mysql_query($sql);

--- End Message ---
--- Begin Message ---
On Tue, Jul 21, 2009 at 12:26 PM, Miller,
Terion<tmil...@springfi.gannett.com> wrote:
> Why isn't this working for searching?

Check your concatenation in the query. You need some white space
padding your SQL segments, otherwise the text all starts to run
together.

 (I had to reformat it. For some reason, most of the code snippets you
post end up all run together on a single line, at least in Gmail.)

<?php

  // Run query on submitted values. Store results in $SESSION and
redirect to restaurants.php
  $sql = "SELECT name, address, inDate, inType, notes, critical,
cviolations, noncritical
          FROM restaurants, inspections
          WHERE restaurants.name <> ''
            AND restaurant.ID = inspection.ID";

  if ($searchName)    {
// ADDED SPACE HERE
      $sql .= " AND restaurants.name LIKE '%".
mysql_real_escape_string($name) ."%' ";
      if(count($name2) == 1)    {
// ADDED SPACE HERE
          $sql .= " AND restaurants.name LIKE '%".
mysql_real_escape_string($name2[1]) ."%' ";
      }    else    {
          foreach($name2 as $namePart)        {
// ADDED SPACE HERE
              $sql .= " AND restaurants.name LIKE '%".
mysql_real_escape_string($namePart) ."%' ";
          }
      }
  }

  if ($searchAddress) {
// ADDED SPACE HERE
      $sql .= " AND restaurants.address LIKE '%".
mysql_real_escape_string($address) ."%' ";
  }
// ADDED SPACE HERE
  $sql .= " ORDER BY restaurants.name;";
  $result = mysql_query($sql);


Andrew

--- End Message ---
--- Begin Message ---
>
> Why isn't this working for searching?
>
>   // Run query on submitted values. Store results in $SESSION and redirect
> to restaurants.php        $sql = "SELECT name, address, inDate, inType,
> notes, critical, cviolations, noncritical FROM restaurants, inspections
> WHERE restaurants.name <> '' AND restaurant.ID = inspection.ID";    if
> ($searchName)    {     $sql .= "AND restaurants.name LIKE '%".
> mysql_real_escape_string($name) ."%' ";        if(count($name2) == 1)    {
>      $sql .= "AND restaurants.name LIKE '%".
> mysql_real_escape_string($name2[1]) ."%' ";    }    else    {
>  foreach($name2 as $namePart)        {        $sql .= "AND
> restaurants.name LIKE '%". mysql_real_escape_string($namePart) ."%' ";
>    }    }    }    if ($searchAddress) {        $sql .= "AND
> restaurants.address LIKE '%". mysql_real_escape_string($address) ."%' ";
>  }               $sql .= "ORDER BY restaurants.name;";
>  $result = mysql_query($sql);
>
I'm not sure about MySQL, but in Informix my queries will crash when trying
to just append the ORDER BY clause by itself.

$sql .= "ORDER BY restaurants.name;";

Also, you have a semi colon before and after the ending quote.

TRY

$sql .= "AND 1 = 1
ORDER BY restaurants.name";

--- End Message ---
--- Begin Message ---


On 7/21/09 11:47 AM, "Dan Shirah" <mrsqua...@gmail.com> wrote:

Why isn't this working for searching?

  // Run query on submitted values. Store results in $SESSION and redirect to 
restaurants.php        $sql = "SELECT name, address, inDate, inType, notes, 
critical, cviolations, noncritical FROM restaurants, inspections WHERE 
restaurants.name <http://restaurants.name/><http://restaurants.name/>  <> '' 
AND restaurant.ID = inspection.ID";    if ($searchName)    {     $sql .= "AND 
restaurants.name <http://restaurants.name/><http://restaurants.name/>  LIKE 
'%". mysql_real_escape_string($name) ."%' ";        if(count($name2) == 1)    { 
       $sql .= "AND restaurants.name 
<http://restaurants.name/><http://restaurants.name/>  LIKE '%". 
mysql_real_escape_string($name2[1]) ."%' ";    }    else    {        
foreach($name2 as $namePart)        {        $sql .= "AND restaurants.name 
<http://restaurants.name/><http://restaurants.name/>  LIKE '%". 
mysql_real_escape_string($namePart) ."%' ";        }    }    }    if 
($searchAddress) {        $sql .= "AND restaurants.address LIKE '%". 
mysql_real_escape_string($address) ."%' ";    }               $sql .= "ORDER BY 
restaurants.name <http://restaurants.name/><http://restaurants.name/> ;";       
         $result = mysql_query($sql);
I'm not sure about MySQL, but in Informix my queries will crash when trying to 
just append the ORDER BY clause by itself.

$sql .= "ORDER BY restaurants.name 
<http://restaurants.name><http://restaurants.name> ;";

Also, you have a semi colon before and after the ending quote.

TRY

$sql .= "AND 1 = 1
ORDER BY restaurants.name <http://restaurants.name><http://restaurants.name> ";







Got the query to this point now:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result 
resource in 
/var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.php
 on line 119

--- End Message ---
--- Begin Message ---


On 7/21/09 12:04 PM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:

On Tue, 2009-07-21 at 12:59 -0400, Miller, Terion wrote:
>
>
> On 7/21/09 11:47 AM, "Dan Shirah" <mrsqua...@gmail.com> wrote:
>
> Why isn't this working for searching?
>
>   // Run query on submitted values. Store results in $SESSION and redirect to 
> restaurants.php        $sql = "SELECT name, address, inDate, inType, notes, 
> critical, cviolations, noncritical FROM restaurants, inspections WHERE 
> restaurants.name 
> <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
>   <> '' AND restaurant.ID = inspection.ID";    if ($searchName)    {     $sql 
> .= "AND restaurants.name 
> <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
>   LIKE '%". mysql_real_escape_string($name) ."%' ";        if(count($name2) 
> == 1)    {        $sql .= "AND restaurants.name 
> <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
>   LIKE '%". mysql_real_escape_string($name2[1]) ."%' ";    }    else    {     
>    foreach($name2 as $namePart)        {        $sql .= "AND restaurants.name 
> <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
>   LIKE '%". mysql_real_escape_string($namePart) ."%' ";        }    }    }    
> if ($searchAddress) {        $sql .= "AND restaurants.address LIKE '%". 
> mysql_real_escape_string($address) ."%' ";    }               $sql .= "ORDER 
> BY restaurants.name 
> <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
>  ;";                $result = mysql_query($sql);
> I'm not sure about MySQL, but in Informix my queries will crash when trying 
> to just append the ORDER BY clause by itself.
>
> $sql .= "ORDER BY restaurants.name 
> <http://restaurants.name><http://restaurants.name><http://restaurants.name><http://restaurants.name>
>  ;";
>
> Also, you have a semi colon before and after the ending quote.
>
> TRY
>
> $sql .= "AND 1 = 1
> ORDER BY restaurants.name 
> <http://restaurants.name><http://restaurants.name><http://restaurants.name><http://restaurants.name>
>  ";
>
>
>
>
>
>
>
> Got the query to this point now:
>
> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result 
> resource in 
> /var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.php
>  on line 119
>
That means your query is invalid. Try printing the query out and posting
it here so that we can see it.

Thanks
Ash
www.ashleysheridan.co.uk



I Got this error when I echo'd the sql $results ;
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 'restaurants.name LIKE 
'%A%' AND restaurants.name LIKE '%A%' ORDER BY restaurants' at line 1

--- End Message ---
--- Begin Message ---
Turned off the redirects on the whole script and tried to the the query to echo 
and these are the errors I got:

Notice: Undefined offset: 1 in 
/var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.php
 on line 89

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result 
resource in 
/var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.php
 on line 119


On 7/21/09 11:32 AM, "Kevin Smith" <ke...@netsmith.ltd.uk> wrote:

Can you supply the actual generated SQL, I can potentially see a
problem, but need to see the final SQL statement.

Miller, Terion wrote:
> Why isn't this working for searching?
>
>     // Run query on submitted values. Store results in $SESSION and redirect 
> to restaurants.php        $sql = "SELECT name, address, inDate, inType, 
> notes, critical, cviolations, noncritical FROM restaurants, inspections WHERE 
> restaurants.name<>  '' AND restaurant.ID = inspection.ID";    if 
> ($searchName)    {     $sql .= "AND restaurants.name LIKE '%". 
> mysql_real_escape_string($name) ."%' ";        if(count($name2) == 1)    {    
>     $sql .= "AND restaurants.name LIKE '%". 
> mysql_real_escape_string($name2[1]) ."%' ";    }    else    {        
> foreach($name2 as $namePart)        {        $sql .= "AND restaurants.name 
> LIKE '%". mysql_real_escape_string($namePart) ."%' ";        }    }    }    
> if ($searchAddress) {        $sql .= "AND restaurants.address LIKE '%". 
> mysql_real_escape_string($address) ."%' ";    }               $sql .= "ORDER 
> BY restaurants.name;";                $result = mysql_query($sql);
>
>





--- End Message ---
--- Begin Message ---
On Tue, Jul 21, 2009 at 12:41 PM, Miller, Terion <
tmil...@springfi.gannett.com> wrote:

> Turned off the redirects on the whole script and tried to the the query to
> echo and these are the errors I got:
>
> Notice: Undefined offset: 1 in /var/www/vhosts/
> getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.phpon
>  line 89
>
> Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
> resource in /var/www/vhosts/
> getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.phpon
>  line 119
>
>
> On 7/21/09 11:32 AM, "Kevin Smith" <ke...@netsmith.ltd.uk> wrote:
>
> Can you supply the actual generated SQL, I can potentially see a
> problem, but need to see the final SQL statement.
>
> print_r($sql);

--- End Message ---
--- Begin Message ---
Here it is...I see where it's doing the restaurant.name LIKE statement 2x which 
is prob messing it up right...but in the code why is it doing that twice..

SELECT name, address, inDate, inType, notes, critical, cviolations, noncritical 
FROM restaurants, inspections WHERE restaurants.name <> '' AND restaurant.ID = 
inspection.IDAND restaurants.name LIKE '%A%' AND restaurants.name LIKE '%A%' 
ORDER BY restaurants.name;


On 7/21/09 12:11 PM, "Dan Shirah" <mrsqua...@gmail.com> wrote:

print_r($sql);


--- End Message ---
--- Begin Message ---
On Tue, 2009-07-21 at 10:07 -0700, Miller, Terion wrote:
> 
> 
> On 7/21/09 12:04 PM, "Ashley Sheridan" <a...@ashleysheridan.co.uk> wrote:
> 
> On Tue, 2009-07-21 at 12:59 -0400, Miller, Terion wrote:
> >
> >
> > On 7/21/09 11:47 AM, "Dan Shirah" <mrsqua...@gmail.com> wrote:
> >
> > Why isn't this working for searching?
> >
> >   // Run query on submitted values. Store results in $SESSION and redirect 
> > to restaurants.php        $sql = "SELECT name, address, inDate, inType, 
> > notes, critical, cviolations, noncritical FROM restaurants, inspections 
> > WHERE restaurants.name 
> > <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
> >   <> '' AND restaurant.ID = inspection.ID";    if ($searchName)    {     
> > $sql .= "AND restaurants.name 
> > <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
> >   LIKE '%". mysql_real_escape_string($name) ."%' ";        if(count($name2) 
> > == 1)    {        $sql .= "AND restaurants.name 
> > <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
> >   LIKE '%". mysql_real_escape_string($name2[1]) ."%' ";    }    else    {   
> >      foreach($name2 as $namePart)        {        $sql .= "AND 
> > restaurants.name 
> > <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
> >   LIKE '%". mysql_real_escape_string($namePart) ."%' ";        }    }    }  
> >   if ($searchAddress) {        $sql .= "AND restaurants.address LIKE '%". 
> > mysql_real_escape_string($address) ."%' ";    }               $sql .= 
> > "ORDER BY restaurants.name 
> > <http://restaurants.name/><http://restaurants.name/><http://restaurants.name/><http://restaurants.name/>
> >  ;";                $result = mysql_query($sql);
> > I'm not sure about MySQL, but in Informix my queries will crash when trying 
> > to just append the ORDER BY clause by itself.
> >
> > $sql .= "ORDER BY restaurants.name 
> > <http://restaurants.name><http://restaurants.name><http://restaurants.name><http://restaurants.name>
> >  ;";
> >
> > Also, you have a semi colon before and after the ending quote.
> >
> > TRY
> >
> > $sql .= "AND 1 = 1
> > ORDER BY restaurants.name 
> > <http://restaurants.name><http://restaurants.name><http://restaurants.name><http://restaurants.name>
> >  ";
> >
> >
> >
> >
> >
> >
> >
> > Got the query to this point now:
> >
> > Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result 
> > resource in 
> > /var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.php
> >  on line 119
> >
> That means your query is invalid. Try printing the query out and posting
> it here so that we can see it.
> 
> Thanks
> Ash
> www.ashleysheridan.co.uk
> 
> 
> 
> I Got this error when I echo'd the sql $results ;
> 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 'restaurants.name 
> LIKE '%A%' AND restaurants.name LIKE '%A%' ORDER BY restaurants' at line 1
> 
Yes, but that's not your query. The problem is with your query. If you
echo the query, we can see where it might be falling over.

Thanks
Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
On Tue, Jul 21, 2009 at 1:20 PM, Miller,
Terion<tmil...@springfi.gannett.com> wrote:
> Here it is...I see where it's doing the restaurant.name LIKE statement 2x 
> which is prob messing it up right...but in the code why is it doing that 
> twice..
>
> SELECT name, address, inDate, inType, notes, critical, cviolations, 
> noncritical FROM restaurants, inspections WHERE restaurants.name <> '' AND 
> restaurant.ID = inspection.IDAND restaurants.name LIKE '%A%' AND 
> restaurants.name LIKE '%A%' ORDER BY restaurants.name;
>
>

It's not the multiple LIKE statements. It is the concatenation, like I
said the last time. There is no white space between "inspection.ID"
and "AND".

You may indeed have problems with some of those repeated conditions on
restaurants.name, but if so they will be performance issues resulting
from table scans, and not the errors you are reporting.

Andrew

--- End Message ---
--- Begin Message ---
On Tue, 2009-07-21 at 12:59 -0400, Miller, Terion wrote:
> 
> 
> On 7/21/09 11:47 AM, "Dan Shirah" <mrsqua...@gmail.com> wrote:
> 
> Why isn't this working for searching?
> 
>   // Run query on submitted values. Store results in $SESSION and redirect to 
> restaurants.php        $sql = "SELECT name, address, inDate, inType, notes, 
> critical, cviolations, noncritical FROM restaurants, inspections WHERE 
> restaurants.name <http://restaurants.name/><http://restaurants.name/>  <> '' 
> AND restaurant.ID = inspection.ID";    if ($searchName)    {     $sql .= "AND 
> restaurants.name <http://restaurants.name/><http://restaurants.name/>  LIKE 
> '%". mysql_real_escape_string($name) ."%' ";        if(count($name2) == 1)    
> {        $sql .= "AND restaurants.name 
> <http://restaurants.name/><http://restaurants.name/>  LIKE '%". 
> mysql_real_escape_string($name2[1]) ."%' ";    }    else    {        
> foreach($name2 as $namePart)        {        $sql .= "AND restaurants.name 
> <http://restaurants.name/><http://restaurants.name/>  LIKE '%". 
> mysql_real_escape_string($namePart) ."%' ";        }    }    }    if 
> ($searchAddress) {        $sql .= "AND restaurants.address LIKE '%". 
> mysql_real_escape_string($address) ."%' ";    }               $sql .= "ORDER 
> BY restaurants.name <http://restaurants.name/><http://restaurants.name/> ;";  
>               $result = mysql_query($sql);
> I'm not sure about MySQL, but in Informix my queries will crash when trying 
> to just append the ORDER BY clause by itself.
> 
> $sql .= "ORDER BY restaurants.name 
> <http://restaurants.name><http://restaurants.name> ;";
> 
> Also, you have a semi colon before and after the ending quote.
> 
> TRY
> 
> $sql .= "AND 1 = 1
> ORDER BY restaurants.name <http://restaurants.name><http://restaurants.name> 
> ";
> 
> 
> 
> 
> 
> 
> 
> Got the query to this point now:
> 
> Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result 
> resource in 
> /var/www/vhosts/getpublished.news-leader.com/httpdocs/ResturantInspections/processRestaurantSearch.php
>  on line 119
> 
That means your query is invalid. Try printing the query out and posting
it here so that we can see it.

Thanks
Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
On Tue, 2009-07-21 at 13:24 -0400, Andrew Ballard wrote:
> On Tue, Jul 21, 2009 at 1:20 PM, Miller,
> Terion<tmil...@springfi.gannett.com> wrote:
> > Here it is...I see where it's doing the restaurant.name LIKE statement 2x 
> > which is prob messing it up right...but in the code why is it doing that 
> > twice..
> >
> > SELECT name, address, inDate, inType, notes, critical, cviolations, 
> > noncritical FROM restaurants, inspections WHERE restaurants.name <> '' AND 
> > restaurant.ID = inspection.IDAND restaurants.name LIKE '%A%' AND 
> > restaurants.name LIKE '%A%' ORDER BY restaurants.name;
> >
> >
> 
> It's not the multiple LIKE statements. It is the concatenation, like I
> said the last time. There is no white space between "inspection.ID"
> and "AND".
> 
> You may indeed have problems with some of those repeated conditions on
> restaurants.name, but if so they will be performance issues resulting
> from table scans, and not the errors you are reporting.
> 
> Andrew
> 

It's always better putting in extra whitespace at both ends of each part
of the query you are concatenating if you're unsure. Like Andrew said,
MySQL will balk if you have none between keywords, but I've never heard
it complaining about an extra space or two!

Thanks
Ash
www.ashleysheridan.co.uk


--- End Message ---
--- Begin Message ---
Has anyone come across / written a script that will convert one
"flavor" or Dialect of SQL to another?

I need to convert Visual FoxPro 6.0 style WHERE clauses to MySQL.

For the most part the problems are converting VFP functions to the
equivalent SQL. For example, Visual FoxPro has a function inlist()
that is used like inlist(X,1,2,3) which converts to the MySQL query "X
IN (1,2,3)". That's easy enough (relatively speaking) but VFP also has
stuff like "EMPTY(X)" where any of Null, the Empty String (for Char),
0000-00-00 (or the VFP equivalent anyways for dates), False (for
Boolean), 0 (for Numeric) are considered empty without needing to
know the data type. So that starts getting a lot more complex since I'd
need to check the data type of the field in the "right" table... to be
able to convert it to something like (X is null OR X="") or (X is null
OR x=0) etc...

These are for customer "stored" queries... I've already manually
converted "system" queries and I'm frustrated to the point of giving
up and adding a column "untested" and let the end user figure it out
but that seems bad from the standpoint of "lazy" and "poor customer
experience".

Thanks!

Matt

P.S. I'm also going to post this to the MySQL general list but my fear
is that they MIGHT say "We only know MySQL so we can't help you with
that other DBMS" I'm hoping that by posting here someone might say
"well it's not to MySQL but I ran script XYZ to convert my VFP to
PostgreSQL..." or similar.

--- End Message ---

Reply via email to