Results 1 to 14 of 14

Thread: MySQL (and PHP)

  1. #1
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts

    MySQL (and PHP)

    I'd like to learn how to use MySQL, since it would be useful to be able to implement a database driven website. Does anybody know of any decent resources online that will help me use it in conjunction with PHP?

    While I'm at it, are there any good resources for installation on an Apache server?

    Thanks

    Mike
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

  2. #2
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    use wampserver.com to set up an Apache, MySQL and PHP setup. If you want to understand how it hangs to gether download the elements indivdually and google for a guide, there are loads out there.

    For starting from scratch try the Sitepoint book at http://www.sitepoint.com/books/phpmysql1/. The sample chapters should get you going but I recommend the book

  3. #3
    Senior Member Kezzer's Avatar
    Join Date
    Sep 2003
    Posts
    4,863
    Thanks
    12
    Thanked
    5 times in 5 posts
    sitepoint are excellent, they do some awesome books as well

    EDIT: Gah, beat me to it by a second

  4. #4
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts
    Quote Originally Posted by Iain
    use wampserver.com to set up an Apache, MySQL and PHP setup. If you want to understand how it hangs to gether download the elements indivdually and google for a guide, there are loads out there.
    Thanks, forgot to mention that I already have an Apache server with PHP working. (Edit: On Debian)

    And thanks to both of you for the site - I'll have a look.
    Last edited by mike_w; 26-08-2005 at 03:44 PM.
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

  5. #5
    Flak Monkey! Dorza's Avatar
    Join Date
    Jul 2003
    Location
    UK - South Wales
    Posts
    1,762
    Thanks
    34
    Thanked
    17 times in 15 posts
    • Dorza's system
      • Motherboard:
      • Asus P5B Deluxe - WiFi
      • CPU:
      • Q6600 @ 3.06Ghz
      • Memory:
      • 2GB Crucial
      • Storage:
      • 500GB Samsung SpinPoint
      • Graphics card(s):
      • Geforce 9600GT
      • PSU:
      • Cosair HX520W
      • Case:
      • LianLi something something or other
      • Monitor(s):
      • Eizo FlexScan S1910 (1280*1024)
      • Internet:
      • 2mb Virgin (when they want to give me that: else 1mb)
    You might want to look at the PHP Anthology books from site point as well mike_w. I would also recommend the book Iain linked to. Its a very good thorough read and starts you off in the right direction. In short, sitepoint has you covered

    PS. Beginning PHP5 and MySQL is a good book as well, but this is more of a reference book i feel. Note: the link i just give is for the 2nd edition which is not yet out.

    Dorza
    Last edited by Dorza; 26-08-2005 at 09:39 PM.

  6. #6
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    The PHP Manual is a great reference with plenty of examples, toy around with some ideas, the MySQL docs aren't *as* clean, but still helpful for constructing complex queries. phpMyAdmin is also handy if the commandline mysql client annoys you.

    And of course, Google is always your friend
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  7. #7
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts
    Okay, managed to get a small database going, but I've got a problem with a SELECT bit. Here's the first part of the PHP:

    Code:
    <?php $mysqlconnect = @mysql_connect('localhost', 'root', 'baz');
    
    $dbconnect = @mysql_select_db('database');
    
    $name = $_GET['n'];
    
    $result = @mysql_query('SELECT * FROM foobar WHERE (name = $name)');
    
    $row = mysql_fetch_array($result);
    
    ?>
    The address is page.php?n=foo. The idea is to grab just the one row from a table. The problem is with name=$name. When I substitute $name for an actual name in the table, it works fine, yet with $name, it can't find the row. When I do an echo showing $name, $name is the right value.

    An example of where the row is being used:

    Code:
    <?php echo $row['title']; ?>
    Any help is appreciated.

    Edit: Solved it by changing it to: $result = @mysql_query("SELECT * FROM websitearticles WHERE (name = '$name')");
    Last edited by mike_w; 26-08-2005 at 10:43 PM.
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

  8. #8
    Bigger than Jesus Norky's Avatar
    Join Date
    Feb 2005
    Posts
    1,579
    Thanks
    1
    Thanked
    8 times in 8 posts
    Best thing to do is put your query into a string, then you can recall it for debugging purposes

    $sql = "Your query";
    mysql_query($sql) or die($sql);

    Echoing out the string is useful when you've got variables in the query.

  9. #9
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    Code:
    <?php $mysqlconnect = @mysql_connect('localhost', 'root', 'baz');
    $dbconnect = @mysql_select_db('database');
    $name = $_GET['n'];
    $result = @mysql_query('SELECT * FROM foobar WHERE (name = $name)');
    $row = mysql_fetch_array($result);
    ?>
    Should read:
    Code:
    <?php
        $mysqlconnect = mysql_connect("localhost", "root", "baz");
        $db = mysql_select_db("database");
        $name = $_GET['n'];
        $result = mysql_query("SELECT * FROM foobar WHERE name='$name'");
        $row = mysql_fetch_array($result);
    ?>
    note, WHERE clause variables need to be quoted, I use " quotes in php code/functions, and ' for sql queries, thats just me though.. this *should* work, keep it up.

    the @ just suppresses function warnings/errors, might want to keep them out for learning, so if you bugger something up it'll help explain what went wrong.
    Last edited by aidanjt; 26-08-2005 at 11:02 PM.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  10. #10
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts
    Thanks again for the help.

    Quote Originally Posted by aidanjt
    the @ just suppresses function warnings/errors, might want to keep them out for learning, so if you bugger something up it'll help explain what went wrong.
    Yup, the ones with the @ in front are the ones I've written error messages for - just haven't got around to doing them all yet!
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

  11. #11
    HEXUS.net Webmaster
    Join Date
    Jul 2003
    Location
    UK
    Posts
    3,108
    Thanks
    1
    Thanked
    0 times in 0 posts
    The MySQL docs aren't as useful as the PHP ones until you make compressed help manual (.chm file) which is easy to do. I've built one recently, get it here -> www.hexus.net/iain/mysql_5_0_3.chm

  12. #12
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts
    Right then, a couple of questions:

    1) If I were to have various sections on a website, such as a section for hardware and one for software, would I create one table and put all the articles together, seperating them by creating a category column? Or would it be better to create individual tables for each section? I'm leaning towards a single table, but I'm not really sure.

    2) The point (so far as I can tell) of making a site database driven is to seperate the content and the code. However, for the bodies of articles, I still have things such as <p> and <img> tags - is there a better way of storing them in the database?

    Thanks for all the help
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

  13. #13
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    1) I'd keep everything in the same table, after all, if you make two tables they're going to have the same data structure, no point segregating them.
    2) you can either make your own tag formats for storing (much like vBulletin), or just allow storage of simple html tags.. whatever works best for you. The latter is less work.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  14. #14
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts
    Quote Originally Posted by aidanjt
    2) you can either make your own tag formats for storing (much like vBulletin), or just allow storage of simple html tags.. whatever works best for you. The latter is less work.
    Hmm... I think I'll go for the HTML tags - it allows me to retain control over the page, as well as not having to use special tag formats all the time.
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Learn PHP & MySQL
    By Matt1eD in forum Software
    Replies: 0
    Last Post: 23-06-2005, 05:01 PM
  2. Another MySQL Help Thread
    By r1zeek in forum Software
    Replies: 2
    Last Post: 11-07-2004, 07:32 PM
  3. Newbie questions about phpBB and MySQL
    By Allen in forum Networking and Broadband
    Replies: 6
    Last Post: 24-04-2004, 06:53 PM
  4. PHP and MySQL
    By Kezzer in forum Software
    Replies: 4
    Last Post: 28-10-2003, 02:59 PM

Posting Permissions

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