AUTHOR'S MAIN SITE  »  OVERVIEW: client/ server work  »  More general notes on MySQL
Delicious.Com Bookmark this on Delicious    StumbleUpon.Com Recommend to StumbleUpon

Using the MySQL databases allocated to a 1and1.com hosting package

This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a narrow window. With most browsers, pressing plus, minus or zero while the control key (ctrl) is held down will change the texts size. (Enlarge, reduce, restore to default, respectively.) (This is fully explained, and there are more tips, at my Power Browsing page.)

Page contents © TK Boyd, Sheepdog Software, 3/13-3/17.



If you are a MySQL-hungry 1and1.com, or 1and1.co.uk customer...

What is php?

(This page updated 03 Mar 17)

I don't, of course, know how much you know about php. In a nutshell, you put "stuff" in the HTML behind a web page, and "stuff" appears on the screens of anyone accessing the page... BUT!... the stuff on the screen is much different from the stuff in the HTML.

The "Ran for first time..." line below has been done "by hand" with "basic" HTML to duplicated the result obtained with some php I had in my code back in 2013. Sort of a php "Hello World".

Test of php

You'd be amazed how much excitement the following line gave me when some php in a page written by me created it, at the time stated....

Ran for first time: 10 Mar 13, 09:33

... after YEARS of struggle to get to the point where I had ALL the bits learned and in place.

Many thanks to....

Problems with Open Office (rare even back in 2013, VERY rare today (2017)) prompting me to "attack" MySQL... AGAIN... and make progress there, and to...

http://anw.bygsoftware.com/1and1/PhpMySql_Faq1.htm for a post that, when he made it was probably right, and did not need MUCH tweaking, and to...

The EXCELLENT people at 1&1 for their fine service, and their excellent "Help" team. Please, please, please do not abuse the 1&1 help-lines: Call them AFTER trying Google, etc. But they have, many times, been very helpful to me when I have DONE MY HOMEWORK FIRST, and got to the point that I could ask an intelligent question.

You can only do (exactly) what I've done if your 1&1 package is a Linux package. How do you know? If MySQL databases are part of your package, it is a Linux package. (MySQL will run under Windows and Mac... if you set up your own server. And the CLIENT can be on any OS.

The little table below is generated from the data in a MySQL table which resides on a 1and1 server. The PHP script is given below the table, with my database's details (host server, user ID, and passwords need to be replaced with YOUR details.) For the details for YOUR database, go along to the "MySQL Database Set Up and Configuration" page of your 1&1 control panel.

The first parameter for the MYSQL_CONNECT command, the host server parameter, should be filled with what 1&1 call the database's "Host Name". In my case it ended ".perfora.net"

The server(host) name and user name (1st and second parameters for MYSQL_CONNECT) are found on the "MySQL Database Set Up and Configuration" page of your 1&1 control panel. The database password can be set with the "Edit" button at the right hand end of the database's line on the page just mentioned. Note that it can take a minute or two for any change to "be live". Minutes.. not tens of minutes. Refresh the "MySQL Database Set Up and Configuration" page until it shows the database as "ready".

The "database name", needed for MYSQL_SELECT_DB is found in the same place. Note that the 1&1 assigned names for the database and the user are very similar, but not the same... There's an extra character in on, at the second position in the name.

At the server, there now follows a block of code enclosed in ">?php ...... ?<

But, even if you examine the page source, you won't see that code. (I've presented it below, tweaked, by other means.) "The magic" of PHP takes my page, at the server (at 1&1) and dynamically replaces the code with the "stuff" that gives rise to the table's contents. (If I were to change what is in the table, then, if you revisited this page, you would see different records below. Without me making any changes to the html which you use!)

Oh! Out of place, but you need to know: I would, if I were you, if you are new to all of this, SET UP your MySQL database, with it's simple first table, and a few test records, with phpMyAdmin, which you can use via your 1&1 control panel... when you figure it all out. Not easy! But easier than some alternatives!!

Once upon a time, this page had "real" php in it. In 2017, I'm afraid I replaced that with simulations of what the php used to generate. (I decided not to retain my 1and1 php serving opportunities.)

The RESULTS of the PHP code which I finally, 10 Mar 13, got Just Right used to look a bit like.... (SN= "Serial number")

   SN   Name     Rank 
   27   George   Major
   576  Henry    Pvt
   23   Mark     General

When this page was actually driven by php, what you see above was created by php code in the page accessing a database on an 1and1 server, and "injecting" the data into the page served up. People who accessed the page didn't see the php, even if they went to the trouble of using "view page source".

And here's the PHP which generated the above in 2013. (I have redacted my database's name, user name, and password, of course.

"Of course"? Apologies if I offended anyone who doesn't understand. The magic of php is that it creates dynamic web pages. What is on the server does not appear on the client's machine! Some of the stuff on the server (the php code) is REPLACED (according to the dictats of the code) in what is served up to the client. It's what php is all about!) So, if the page you were reading hadn't been "messed with" (by me!), you wouldn't see the following. You would see what something very like the following would generate and insert. So if I am going to show you the php, I need to redact the user ID and password for access to my database, because with them you can not only read the data, but mess with the table. Not something to share across the web!

<?php
     /* Start of PHP4.4.9 Script */
     /* Put data for SQL-server into local variables*/
          $server= "YOUR_HOSTNAME_HERE";  /* "Host name", from 1&1 database admin page*/
          $user= "YOUR_USERNAME_HERE";    /* DATABASE's user name... from 1&1 database admin panel.
                                          NOT FTP user name */
          $password= "YOUR_PASSWORD_HERE";   /* DATABASE's pw: Set with "edit"
                                          button on database at 1&1 database
                                          admin (not phpmyadmin) page...
                                          N.B.: Can take minutes (not tens
                                          of minutes) for edit to be
                                          processed. Refresh admin page
                                          until status= ready*/
          $database= "dbpppppppppp";   /* Name of database pp 1&1 admin page*/
          $table= "Officers";          /* Name of table. Must exist YOUR database*/

     /* Access SQL-Server, query a table */
          MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
          MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");
          $result=MYSQL_QUERY( "SELECT * FROM $table order by name");

     /* Output data into a HTML table */
          echo  "<table  border=\"1\" align=center width=50%";
          echo  "<tr>";
          echo  "<div color=\"#ffff00\">";
          while ($field=mysql_fetch_field($result))  {
                 echo  "<th>$field->name</A></th>";
          }
          echo  "</font></tr>";
          while($row  =  mysql_fetch_row($result))  {
                  echo    "<tr>";
                  for($i=0;  $i < mysql_num_fields($result);  $i++)  {
                       echo    "<td align=center>$row[$i]</td>";
                  }
                  echo    "</tr>\n";
          }
          echo  "</table><BR><BR>";

     /* Close SQL-connection */
          MYSQL_CLOSE();
         ?>

Hope that helps!

Entering data into table....

The following PHP script has not yet been tweaked, debugged, etc, but maybe it will help you, if you want to do it "now". It is mostly just lifted from the excellent contribution to everyone's sanity from...
http://anw.bygsoftware.com/1and1/PhpMySql_Faq1.htm

The script, with a bit of "ad hoc" tweaking should, I think, allow you to add records to a table. I would still advise you to create the table (and before that, the database) "by hand", using the myPHPadmin app from within your 1and1 control panel.

<?php
     /* Start of PHP4.4.9 Script */
     /* Put data for SQL-server into local variables*/
          $server= "mmmmmmmmmmm.net";  /* "Host name", from 1&1 database admin page*/
          $user= "dbonnnnnnnnnnnn";    /* DATABASE's user name... from 1&1 database admin panel.
                                          NOT FTP user name */
          $password= "oooooooooooo";   /* DATABASE's pw: Set with "edit"
                                          button on database at 1&1 database
                                          admin (not phpmyadmin) page...
                                          N.B.: Can take minutes (not tens
                                          of minutes) for edit to be
                                          processed. Refresh admin page
                                          until status= ready*/
          $database= "dbpppppppppp";   /* Name of database pp 1&1 admin page*/
          $table= "Officers";          /* Name of table. Must exist YOUR database*/

     /* Access SQL-server */
          MYSQL_CONNECT($server, $user, $password) or die ( "<H3>Server unreachable</H3>");
          MYSQL_SELECT_DB($database) or die ( "<H3>Database non existent</H3>");

     /* Enter the new records.... here are the lines you
             would replace with a "hand tweak" each time you
             wanted to add new records to the table....
             We see two lines as examples; each adds a record.*/
          MYSQL_QUERY( "INSERT INTO $table
                 VALUES('OneandOne','info@oneandone.co.uk')");
          MYSQL_QUERY( "INSERT INTO $table
                 VALUES('Enders Game','orson.scott@card.com')");

     /* Optional "frill"...
        Display number of entries */
           $number=MYSQL_NUMROWS(MYSQL_QUERY( "SELECT * FROM $table"));
           if ($number==0):
              echo  "database empty";
           elseif ($number > 0):
              echo  "$number rows in database";
           endif;

     /* Close SQL-Connection */
          MYSQL_CLOSE();
         ?>

The script is not at all user friendly, in that you get no feedback when an attempted Insert Into fails... be it due to a typo in the relevant line, or because you are attempting to add a new record with a previously used value in the primary key field... but, in it's own crude way, the script does work! (^_^)

That's all, folks...

For more "gems" from the same author, visit my main page?

Although THIS page doesn't really deserve it yet, I have put the following button in as part of the page building process. Have you heard of Flattr? Great new idea to make it easy for you to send small thank you$ to people who provide Good Stuff on the web. If you want to send $$erious thank yous, there are better ways, but for a small "tip" here and there, Flattr ticks a lot of boxes which no one else has found a way to do yet. Please at least check out my introduction to Flattr, if you haven't heard of it? "No obligation", as they say!





Editorial Philosophy

I dislike 'fancy' websites more concerned with a flashy appearance than for good content. For a pretty picture, I can go to an art gallery. Not everyone has fast broadband.

I present this material in a format aimed at to helping you USE it. There are two aspects to that: The way it is split up, and the way it is posted..

Please remember the material is copyright. (TK Boyd, 2006 and later) The procedures in the page just cited are suggested only for convenient personal use of the material, however, also....

Feel free to use this information in computer courses, etc, but a credit of the source, quoting the URL, would be appreciated. If you simply copy the pages to other web pages you will do your readers a disservice: Your copies won't stay current. Far better to link to the original pages, and then your readers will see up-to-date versions. For those who care- thank you. I have posted a page with more information on what copyright waivers I extend, and suggestions for those who wish to put this material on CDs, etc. (There is at least one prison using Sheepdog Software/ Sheepdog Guides material for inmate education. Situations do exist where good internet connections are not possible!)

Translations are welcomed. Tell me about yours, so I can post links to it. (More information at the page about copyright waivers.)




Ad from page's editor: Yes.. I do enjoy compiling these things for you... I hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!

PLEASE >>> Click here to visit editor's Sheepdog Software (tm) freeware, shareware pages <<< PLEASE


If you liked this tutorial, see my main webpage for more things from the same author.

Editor's email address. Suggestions welcomed!     - - -    Want a site hosted, or email? I like 1&1's services.




Valid HTML 4.01 Transitional Page WILL BE tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes. There were two "unknown attributes" in Google+ button code. Sigh.


One last bit of advice: Be sure you know all you need to about spyware.

. . . . . P a g e . . . E n d s . . . . .