SitePoint Sponsor

User Tag List

Results 1 to 19 of 19

Hybrid View

  1. #1
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What's the difference?

    What's the difference between using "mysql_query" and "$sql"?
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  2. #2
    Digital Warrior Renegade's Avatar
    Join Date
    Nov 2000
    Location
    Portland, OR
    Posts
    480
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <sarcasm>
    one's a function and one's a variable
    </sarcasm>

    heh, uhhh do you mean what the difference between:

    $result = mysql_query("SELECT * FROM users");

    and

    $sql = "SELECT * FROM users";
    $result = mysql_query($sql);

    Is that what your asking?

  3. #3
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah.

    There are a lot of scripts out there that define the query in a variable (often times called $sql); that's what Adam's asking (right?)

    Essentially, Renegade is correct. One is simply a variable, while the other is the actual query command.

    It makes it easier (generally) if you use something like:
    PHP Code:
    $sql = @mysql_query("select * from whatever"); 
    Because you can call what's returned easier by simply returning to the variable $sql (or whatever variable you decide to use).

    I usually use variables to define the connection, the database selection, the query strings, and the returned results, just because it makes it so much easier to work with and call back the functions with the variables later in the script.

    P.S. Adam, how's the PHP/MySQL coming along? If you need help, just ask me! Two months ago I was just starting with MySQL like you, and a few weeks ago it "just clicked!" I have almost an entire database driven site I'm working on (my district key club site), and I didn't even have to refer back to any tutorials! It's neat!

    Last edited by Aes; Sep 23, 2001 at 01:45.
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  4. #4
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Renegade
    heh, uhhh do you mean what the difference between:

    $result = mysql_query("SELECT * FROM users");

    and

    $sql = "SELECT * FROM users";
    $result = mysql_query($sql);

    Is that what your asking?
    Exactly what I meant. O.K., so in: "$result = mysql_query("SELECT * FROM users");", what does the variable "result" hold?

    And in "$sql = "SELECT * FROM users";", what does the variable "sql" hold? I'm still confused.
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  5. #5
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sql = "SELECT * FROM users";

    $sql is just a variable containing SELECT * FROM users, to run this query you have to use one of the MySQL functions

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature

  6. #6
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Aes
    P.S. Adam, how's the PHP/MySQL coming along? If you need help, just ask me! Two months ago I was just starting with MySQL like you, and a few weeks ago it "just clicked!" I have almost an entire database driven site I'm working on (my district key club site), and I didn't even have to refer back to any tutorials! It's neat!
    It's actually coming o.k. I'm just confused about some things, but I think I have an o.k. plan ready for databasing Help!4Newbies.

    Here it is, what do you think?
    Code:
    |ID|Category|Date Submitted|SigID|Title|Tutorial|
    -------------------------------------------------
    |&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
    |&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
    |&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|
    etc.
    -------------------------------------------------
    Then I will pull out the tuts by Category. The "SigID" column will be connected to a seperate table where I can enter peoples sig. choices.

    Tell me what you think.
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  7. #7
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by seanf
    $sql = "SELECT * FROM users";

    $sql is just a variable containing SELECT * FROM users, to run this query you have to use one of the MySQL functions

    Sean
    ooooh, now I think I get it.

    So in:
    $result = mysql_query("SELECT * FROM users");
    "result" holds everything from the users table, right?

    and then in:
    $sql = "SELECT * FROM users";
    $result = mysql_query($sql);
    "sql" holds the "what to do" part and
    "result" holds everything from the users table?

    So, what is the advantage of using the second one? The first is shorter.
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  8. #8
    1-800-JMULDER JMulder's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,745
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The second is is easier to change, say if you do multiple queries on one page you can call the $sql variable, if you ever need to change query, you can change the $sql variable. But with the first one you would need to change it all over the script.

    That's why I would use it for
    Jeroen Mulder

    w: www.jeroenmulder.com

  9. #9
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by JMulder
    The second is is easier to change, say if you do multiple queries on one page you can call the $sql variable, if you ever need to change query, you can change the $sql variable. But with the first one you would need to change it all over the script.

    That's why I would use it for
    I see, thanks! It's all getting to click, I'm excited!
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  10. #10
    1-800-JMULDER JMulder's Avatar
    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    1,745
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh cool..enjoy

    Woah..I actually wrote is is ? Grr..
    Jeroen Mulder

    w: www.jeroenmulder.com

  11. #11
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That looks like it will work well Adam. If you run into any problems, send me a PM or e-mail me. I'll be glad to help in any way!
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  12. #12
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys!

    Actually, one more question. I downloaded phpdev3. When I open mysql.exe, it automatically connects to my localhost. But I want to connect to my sites hosts server. Does anyone know what to do?
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  13. #13
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't use your mysql.exe from your computer to connect, plus it wouldn't be secure.

    I use Putty, it's a nifty little SSH1/SSH2 client -- you're server or hosting provider should support it -- give it a try:
    http://people.nl.linux.org/~bjs/putty/
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.

  14. #14
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use the OpenSSH port to Windows by Cygwin.

    Here's a package that installs it automatically for you, includes the SSH server as well as client, although you'll probably be only interested in the client:

    http://www.networksimplicity.com/openssh/

  15. #15
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, my host has phpMyAdmin that I can use. Do you think that will be good enough for what I'm trying to do?
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  16. #16
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    phpMyAdmin will probably be OK for most things you wanna do, and may do it quicker as well.

    I normally use the SSH shells when I need to use commands not supported by phpMyAdmin, or when I need to import a big database backup, I get timeout errors when I try to do it in phpMyAdmin, but in SSH, I can upload to my server and use the shell to import it.

  17. #17
    Former Staff Member silver trophy Adam P.'s Avatar
    Join Date
    Apr 2001
    Location
    San Francisco
    Posts
    3,288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Next question:

    I want to database the site on my own computer first to make sure that I have all of the glitches and stuff worked out before I put it online. Is there a way for me to transfer a database from my computer to my hosts server?
    SPF Mentor/Advisor 2001-2003
    SPF Designer of the Year 2002
    SPF Graphic Designer of the Year 2003
    AdamPolselli.com

  18. #18
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you go to command line and from your local server, you go:

    mysqldump database_name > databasedump.sql

    And in your remote host, you can either use phpMyAdmin to import that database dump, or go:

    mysql < '/path/to/databasedump.sql'

    or use mysqlimport, another way to do is after loggin into mysql, type:

    source '/path/to/databasedump.sql'

    Have to create the database first though I think.

  19. #19
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by swimm5001
    Is there a way for me to transfer a database from my computer to my hosts server?
    You can use phpMyAdmin to do this too, but if your database is big (I think over 7mb) it can cause problems

    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •