View Full Version : Where Do I Place Initial php mySQL Code?
04-06-2009, 04:01 AM
I'm a little lost on something.
I know I can create a database using cpanel's mySQL manager and create and edit a table with myphpadmin, but I want to learn how to program the actual code first...
I've gone through tutorials on php mySQL, and I grasp the language, but I'm failing to read anywhere that answers my following questions...
Where do I put the code for an SQL database and Table and its columns of data for my web site? Do I put the code in its own file and save it as .php? If so, how is the code enacted to actually create the database, table, columns, etc.? Do I include the code in my index page? Is it only supposed to load one time, since the database is created only once? I don't get this aspect of it.
04-06-2009, 07:34 AM
Well, there's a "manual" way to do it, from a command prompt. Of course, this way pretty much sucks monkey butt, so the way I suggest is you use phpMyAdmin to create the tables as you want them, then do an "Export", structure only, and save that to a file. Now, your entire schema can be recreated in seconds-- just import that file (also using phpMyAdmin) and presto, your database is created.
I don't know why you want to mess around with using PHP to create your database, since, as you say, this is something you'll only do once. You certainly wouldn't bother putting create table queries in your index.php file.
04-06-2009, 12:55 PM
Hmmm. Why does the command prompt way suck monkey butt?
I started creating a table in myphpadmin. I didn't totally complete it, so at the bottom of the screen where there's a SAVE button next to "Or Add [number] Field(s), I pushed the SAVE button, but because all of the fields are not filled in, I can't save it. Is there a way to SAVE a partially filled out Table in myphpadmin, to come back to it later?
This is why I want to hand-code everything. These WYSIWYG type programs always fail me. Is the command-prompt way all that hard?
04-06-2009, 04:22 PM
Not "hard", per se, but just more manual. I have no idea why you'd not be able to save your table-- what's the error? You can, incidentally, execute any SQL query (CREATE TABLE being just like any other SQL query) so if you want to write your CREATE TABLE statement by hand, you can still execute it through phpMyAdmin.
You can do the same thing at the command prompt, so if you're more comfortable doing that, feel free.
04-06-2009, 11:17 PM
Ok. I see now where Ican click a "query" icon to pull up a box to write SQL code. I didn't see that option at first. That'll do just fine for programming area.
After creating a table and selecting how many fields I want, a table shows with a bunch of empty fields. Now if I decide to not fill in a field or any field and press the SAVE-button at the bottom of the screen, I get an alert pop-up box that says: "Missing value in the form!" If I fill in just one value, or some values and leave blanks, I get the same message.
Which is why I'm assuming I have to complete the whole table in order to save it, which sucks monkey butt!
Also, when I look in the left column, where the "query" icon is, it says "No tables found in database." I'm guessing that is so because I haven't been able to save the table yet? At the top of the screen, it states the Table name though.
P.s. I just tried something. I created one field and plugged in some values to satisfy a full column being complete. It saved. Is that normal? Should I have to complete the table one field by one field? Or have to create a whole column before it's allowed to be saved?
04-07-2009, 02:01 PM
When you create a new table using phpMyAdmin and provide it with a column count it expects you to supply all of the column details at that time. It can show you the name of the table you will be creating because you've already supplied it but it won't complete the table unless you also supply all of the column definitions for the number of columns you asked for.
You may certainly create columns one at a time but it will likely be a bit tedious. phpMyAdmin makes the assumption that when you create a table with x number of columns you already know how you want those columns defined and expects all of the details before it will actually create the table.
04-07-2009, 03:15 PM
Ok. I'm getting somewhere now. I have some more questions in mind, but I'll take these initials steps first and try to answer them myself as I plug along. Thanks.
02-19-2012, 06:45 PM
hi all i disliked phpMyAdmin's interface so i decided i would built a new MySQL manager like the MySQL query browser. please if you have a change can you give it a try
LIVE DEMO -> http://www.farfile.com/Demos/MyXQuery/
it works like the MySQL query Browser (ctrl+enter to execute a query)
you can right click on the tree for other things too.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.