Web Hosting Forum | Lunarpages

Author Topic: Example of putting Inserting into & Querying a Lunar Pages MySQL DB?  (Read 1208 times)

Offline beforewisdom

  • Newbie
  • *
  • Posts: 4
Hi,

I'm an experienced programmer, who is just starting out learning PHP.  I just finished a tiny intro tutorial and am now moving on to a larger text.

I want to use my Lunar Pages account to practice PHP.

Just dropped a HelloWorld.php file into my public_html folder.....works good.

I was wondering if anyone could give me a boiler plate example of a PHP page that contacts the Lunar Pages MySQL db ( do I need to create one?  docs ? ), inserts a record and queries a record.

If there are docs for this please point me to them.

Thanks either way

Steve

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6231
Re: Example of putting Inserting into & Querying a Lunar Pages MySQL DB?
« Reply #1 on: December 06, 2017, 04:50:19 PM »
Well, you would go into cPanel (or LPCP) and tell it to create a database under a certain name. Then you would create a "user" (with password) and grant them access to this database and grant them "privileges" they need to perform various operations. On the PHP side, make sure you use the MySQLi library, rather than the obsolete MySQL library. You can either google mysql example and mysql tutorial and see some tutorials, or you can obtain a free application (blog, store, forum, etc.) and browse the code to Learn By ExampleTM. The problem with this is that many commercial-grade applications (whether free or not) tend to use some pretty complicated code for highest performance, so they may not be good for a rank beginner. You probably should stick to tutorial pages. You will need to decide on a few simple tables to start off, create .sql code to IMPORT via phpMyAdmin (or use phpMyAdmin's DB editor directly), to create and start populating the database tables. Finally, you can write some PHP code to do an INSERT INTO and a SELECT query. You might want to start off with procedural calls, but you should work your way up to OO coding before long, as that's the preferred way in MySQLi. Before long, you should be starting to make sense of application code that you study.

Not knowing your coding proficiency, your understanding of RDBMS and SQL, or your level of interest and energy, that's about all I can suggest. I think most tutorials would do as good a job as I could in giving some sample code.
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6231
Re: Example of putting Inserting into & Querying a Lunar Pages MySQL DB?
« Reply #2 on: December 07, 2017, 05:20:43 AM »
I forgot to mention a couple of things. When giving your DB name, and user name to PHP to use in the connection calls, they are usually prefixed with your account name and underscore: myacct_myDBname and myacct_myUsername. This is so the MySQL system can tell apart databases and users from different accounts, that happen to have the same DBname or Username. The "location" of the database will be "localhost" on older servers (where MySQL shares the same server as the pages), or a specific name or IP address for newer systems (where MySQL is on its own server). If you've misplaced the instructions you received when you set up your account, ask support.
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline beforewisdom

  • Newbie
  • *
  • Posts: 4
Re: Example of putting Inserting into & Querying a Lunar Pages MySQL DB?
« Reply #3 on: December 08, 2017, 10:40:09 AM »
Thanks much, that was what I needed.  I created database and found some *.sql files on the net and used phpMyAdmin to import it all.

 

Share |