14 Replies Latest reply on Dec 5, 2008 9:20 AM by Newsgroup_User

    MySQL Connection Trouble

    UteFanJason Level 2
      Hello,

      I am trying to access a mysql database and am having trouble. I have been trying to follow the example in PHP Solutions by David Powers but I have gone astray somewhere.

      I get one of two errors each time:

      1. 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 '-clients' at line 1

      or

      2. Warning: mysqli_error() expects exactly 1 parameter, 0 given in . . . \New Site\mysql_check.php on line 12

      Thanks in advance for the help you give.

      Here is the code for the two files involved.
        • 1. Re: MySQL Connection Trouble
          Level 7
          UteFanJason wrote:
          > // --- Prepare the SQL query ---
          > $sql = 'SELECT * FROM tbl-clients';

          A hyphen is an illegal character in a database, table, or column name.

          > // --- Submit the query and capture the result ---
          > $result = $conn->query($sql) or die(mysqli_error());

          It looks as though you have uncovered a mistake in my book. This should be:

          $result = $conn->query($sql) or die($conn->error);

          --
          David Powers, Adobe Community Expert
          Author, "The Essential Guide to Dreamweaver CS4",
          "PHP Solutions" & "PHP Object-Oriented Solutions"
          http://foundationphp.com/
          • 2. Re: MySQL Connection Trouble
            UteFanJason Level 2
            David Powers wrote:

            >A hyphen is an illegal character in a database, table, or column name.

            Thanks, I did not know that. I have only used MS Access before this and hyphens were not illegal and how I would separate words in names. I will switch to underscores.

            >It looks as though you have uncovered a mistake in my book. This should be:
            >
            >$result = $conn->query($sql) or die($conn->error);

            Thanks for the correction. Hope that helps if there will be future editions.
            • 3. Re: MySQL Connection Trouble
              UteFanJason Level 2
              David,

              Another question. As I am getting deeper into login systems and cms I am thinking that it would be a lot better and easier in the long run to use OOP. Would you agree?

              Thanks again.
              • 4. MySQL Connection Trouble
                UteFanJason Level 2
                Oops. This was accidentally submitted twice.
                • 5. Re: MySQL Connection Trouble
                  Level 7
                  UteFanJason wrote:
                  > Another question. As I am getting deeper into login systems and cms I am thinking that it would be a lot better and easier in the long run to use OOP. Would you agree?

                  OOP isn't necessarily better, but it does have the advantage of reusable
                  code. OOP requires a different mindset, and takes quite a lot of getting
                  used to. For small projects, it's probably overkill, but if you're
                  moving into bigger projects, it's definitely something you should think
                  about.

                  --
                  David Powers, Adobe Community Expert
                  Author, "The Essential Guide to Dreamweaver CS4",
                  "PHP Solutions" & "PHP Object-Oriented Solutions"
                  http://foundationphp.com/
                  • 6. Re: MySQL Connection Trouble
                    UteFanJason Level 2
                    Ok. That makes sense.

                    I have used it before but it was years ago in high school for a class on C++. It wasn't too horrible but it was the hardest part of that class. I am nowhere near as familiar with php now as I was with C++ when I started learning OOP for that. I will give it some time then get into it.
                    • 7. Re: MySQL Connection Trouble
                      Level 7
                      UteFanJason wrote:
                      > I have used it before but it was years ago in high school for a class on C++.

                      Well, you have an advantage over me. When I was in high school, pocket
                      calculators still hadn't been invented. ;-)

                      --
                      David Powers, Adobe Community Expert
                      Author, "The Essential Guide to Dreamweaver CS4",
                      "PHP Solutions" & "PHP Object-Oriented Solutions"
                      http://foundationphp.com/
                      • 8. Re: MySQL Connection Trouble
                        Level 7
                        I remember my first glance at a Bowmar Brain - all $400 worth
                        (add/subtract/multiply/divide - that's it!).

                        --
                        Murray --- ICQ 71997575
                        Adobe Community Expert
                        (If you *MUST* email me, don't LAUGH when you do so!)
                        ==================
                        http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                        http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                        ==================


                        "David Powers" <david@example.com> wrote in message
                        news:ggsfhg$pec$2@forums.macromedia.com...
                        > UteFanJason wrote:
                        >> I have used it before but it was years ago in high school for a class on
                        >> C++.
                        >
                        > Well, you have an advantage over me. When I was in high school, pocket
                        > calculators still hadn't been invented. ;-)
                        >
                        > --
                        > David Powers, Adobe Community Expert
                        > Author, "The Essential Guide to Dreamweaver CS4",
                        > "PHP Solutions" & "PHP Object-Oriented Solutions"
                        > http://foundationphp.com/

                        • 9. Re: MySQL Connection Trouble
                          UteFanJason Level 2
                          David Powers wrote:
                          >Well, you have an advantage over me. When I was in high school, pocket
                          calculators still hadn't been invented. ;-)

                          Murray *ACE* wrote:
                          >I remember my first glance at a Bowmar Brain - all $400 worth
                          (add/subtract/multiply/divide - that's it!).

                          It appears that I am a bit younger than you both. I remember when they first started allowing us to use calculators (ok I don't remember what grade but it was early elementary). It was only to learn to use them though. We weren't allowed to use them on homework (which I'm glad about though - the human brain makes for a great simple math calculator most of the time).
                          • 10. Re: MySQL Connection Trouble
                            Level 7
                            David is alot older.... 8)

                            --
                            Murray --- ICQ 71997575
                            Adobe Community Expert
                            (If you *MUST* email me, don't LAUGH when you do so!)
                            ==================
                            http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                            http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                            ==================


                            "UteFanJason" <webforumsuser@macromedia.com> wrote in message
                            news:ggsod0$6ed$1@forums.macromedia.com...
                            > David Powers wrote:
                            > >Well, you have an advantage over me. When I was in high school, pocket
                            > calculators still hadn't been invented. ;-)
                            >
                            > Murray *ACE* wrote:
                            > >I remember my first glance at a Bowmar Brain - all $400 worth
                            > (add/subtract/multiply/divide - that's it!).
                            >
                            > It appears that I am a bit younger than you both. I remember when they
                            > first
                            > started allowing us to use calculators (ok I don't remember what grade but
                            > it
                            > was early elementary). It was only to learn to use them though. We weren't
                            > allowed to use them on homework (which I'm glad about though - the human
                            > brain
                            > makes for a great simple math calculator most of the time).
                            >

                            • 11. Re: MySQL Connection Trouble
                              Level 7
                              Murray *ACE* wrote:
                              > David is alot older.... 8)

                              But younger than Murray. ;-)

                              --
                              David Powers, Adobe Community Expert
                              Author, "The Essential Guide to Dreamweaver CS4",
                              "PHP Solutions" & "PHP Object-Oriented Solutions"
                              http://foundationphp.com/
                              • 12. Re: MySQL Connection Trouble
                                Level 7
                                Speak up, sonny boy.

                                --
                                Murray --- ICQ 71997575
                                Adobe Community Expert
                                (If you *MUST* email me, don't LAUGH when you do so!)
                                ==================
                                http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                                http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                                ==================


                                "David Powers" <david@example.com> wrote in message
                                news:ghbin9$4qg$3@forums.macromedia.com...
                                > Murray *ACE* wrote:
                                >> David is alot older.... 8)
                                >
                                > But younger than Murray. ;-)
                                >
                                > --
                                > David Powers, Adobe Community Expert
                                > Author, "The Essential Guide to Dreamweaver CS4",
                                > "PHP Solutions" & "PHP Object-Oriented Solutions"
                                > http://foundationphp.com/

                                • 13. Re: MySQL Connection Trouble
                                  Level 7
                                  Murray *ACE* wrote:
                                  > Speak up, sonny boy.

                                  YES, GRANDDAD. ;-)

                                  --
                                  David Powers, Adobe Community Expert
                                  Author, "The Essential Guide to Dreamweaver CS4",
                                  "PHP Solutions" & "PHP Object-Oriented Solutions"
                                  http://foundationphp.com/
                                  • 14. Re: MySQL Connection Trouble
                                    Level 7
                                    MUCH BETTER! 8)

                                    --
                                    Murray --- ICQ 71997575
                                    Adobe Community Expert
                                    (If you *MUST* email me, don't LAUGH when you do so!)
                                    ==================
                                    http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
                                    http://www.dwfaq.com - DW FAQs, Tutorials & Resources
                                    ==================


                                    "David Powers" <david@example.com> wrote in message
                                    news:ghbngc$b1m$2@forums.macromedia.com...
                                    > Murray *ACE* wrote:
                                    >> Speak up, sonny boy.
                                    >
                                    > YES, GRANDDAD. ;-)
                                    >
                                    > --
                                    > David Powers, Adobe Community Expert
                                    > Author, "The Essential Guide to Dreamweaver CS4",
                                    > "PHP Solutions" & "PHP Object-Oriented Solutions"
                                    > http://foundationphp.com/