Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

variable interpolation in mysql queries

303 views
Skip to first unread message

Ryan Snow

unread,
Feb 26, 2002, 5:20:01 PM2/26/02
to php...@lists.php.net
Hi, Im kinda new to this list. Can anyone tell me what is the proper way
to interpolate my php variables into my mysql queries?

I've been trying $query = "SELECT password FROM users WHERE login='$login'";


then:
mysql_query($result);
$pd = mysql_result($result);

but I get a message that says: "Supplied Argument is not a valid
MySQL-Link resource"

any ideas, anyone?

Bogdan Stancescu

unread,
Feb 26, 2002, 5:32:00 PM2/26/02
to bog...@lanifex.com, Ryan Snow, php...@lists.php.net
PS. You should consider using mysql_fetch_row() or at least
mysql_fetch_array() for perforance reasons.

B

Bogdan Stancescu wrote:

> $query="query";
> $result=mysql_query($query);
> $pd=mysql_result($result);
>
> Notice the zig-zag - $query is first on the left side, then on the
> right side, then $result is first on the left side, then on the right
> side.
>
> Bogdan

Bogdan Stancescu

unread,
Feb 26, 2002, 5:29:40 PM2/26/02
to Ryan Snow, php...@lists.php.net
$query="query";
$result=mysql_query($query);
$pd=mysql_result($result);

Notice the zig-zag - $query is first on the left side, then on the right
side, then $result is first on the left side, then on the right side.

Bogdan

William Fong

unread,
Feb 26, 2002, 6:16:39 PM2/26/02
to php...@lists.php.net
Would it be faster if all you wanted was one variable, or your SQL statement
only returned on cell?


--
William Fong - wf...@mookandblanchard.com
Phone: 626.968.6424 x210 | Fax: 626.968.6877
Wireless #: 805.490.7732 | Wireless E-mail: 80549...@mobile.att.net


----- Original Message -----
From: "Bogdan Stancescu" <m...@fx.ro>
To: <bog...@lanifex.com>
Cc: "Ryan Snow" <sn...@cosmic.utah.edu>; <php...@lists.php.net>
Sent: Tuesday, February 26, 2002 2:32 PM
Subject: Re: [PHP-DB] variable interpolation in mysql queries


: PS. You should consider using mysql_fetch_row() or at least

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


Ryan Snow

unread,
Feb 26, 2002, 7:15:39 PM2/26/02
to Stewart Gateley, php...@lists.php.net
Cool, I didn't know you could embed mysql_query(...) inside
mysql_fetch_row(...). That's kinda nice--I hate having a line each for
1-connecting, 2-selecting, 3-querying, and 4-resulting. I'll hafta try
that. Thanks.

Ryan

On Tue, 26 Feb 2002, Stewart Gateley wrote:

> First of all that should throw an error, correct syntax is mysql_result
> ($query, 0) meaning to grab the 0 index returned.
>
> I am not sure about performance wise, however I dislike mysql_result
> since if nothing is returned then you get a runtime error. Instead I
> like to use
>
> list($pd) = mysql_fetch_row (
> mysql_query (
> "select password
> from users
> where login = '$login'"
> )
> );
>
> Then you can test $pd without getting sql errors.
>
> -- Stewart


>
> --- Ryan Snow <sn...@cosmic.utah.edu> wrote:
> > Hi, Im kinda new to this list. Can anyone tell me what is the proper
> > way
> > to interpolate my php variables into my mysql queries?
> >
> > I've been trying $query = "SELECT password FROM users WHERE
> > login='$login'";
> >
> >
> > then:
> > mysql_query($result);
> > $pd = mysql_result($result);
> >
> > but I get a message that says: "Supplied Argument is not a valid
> > MySQL-Link resource"
> >
> > any ideas, anyone?
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>

> __________________________________________________
> Do You Yahoo!?
> Yahoo! Greetings - Send FREE e-cards for every occasion!
> http://greetings.yahoo.com
>

Stewart Gateley

unread,
Feb 26, 2002, 7:07:27 PM2/26/02
to Ryan Snow, php...@lists.php.net
First of all that should throw an error, correct syntax is mysql_result
($query, 0) meaning to grab the 0 index returned.

I am not sure about performance wise, however I dislike mysql_result
since if nothing is returned then you get a runtime error. Instead I
like to use

list($pd) = mysql_fetch_row (
mysql_query (
"select password
from users
where login = '$login'"
)
);

Then you can test $pd without getting sql errors.

-- Stewart

--- Ryan Snow <sn...@cosmic.utah.edu> wrote:

0 new messages