|
 |
|
 |
08-18-2004, 01:56 PM
|
#1 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
Mastered the basics, now what?
I've read 2 different PHP tutorials, tested the scripts, made notes and I'm pretty confident now with the basics.
Loops, variables, arrays (numeric indexed and associative), form GET and POST ...
Now what? I wanna build my first database but haven't the foggiest how to get started. Do I create the actual tables in MySQL or Access?
I feel such as fool asking these silly questions.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
08-18-2004, 02:02 PM
|
#2 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
only feel like a fool if you use Access with PHP!!
have you created a database in mysql yet?
do you have a way to administrate mysql besides the command line? if not, go here: http://phpmyadmin.net .. download the latest version, setup the config file, and use it to create a table.
start simple, create a table with a userid, username, and password.
the userid should be an integer, not null, auto increment, and primary key
username should be varchar 16
password should be varchar 32
you can either create that table in phpmyadmin manually, or just copy the following sql :
Code:
CREATE TABLE `user` (
`userid` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`username` VARCHAR( 16 ) NOT NULL ,
`password` VARCHAR( 32 ) NOT NULL ,
PRIMARY KEY ( `userid` )
);
once you have that setup, practice inserting, updating, and deleting records to that table.
if you have questions, of course ask away =)
__________________
Mike
|
|
|
08-18-2004, 02:13 PM
|
#3 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
and here is a sample of a connection and different queries for that structure.
notice that we don't do anything with the 'userid' field when we insert because mysql is automatically assigning the next integer for each new insert.
after you insert a couple users, look at the data and you will see how it works.
PHP Code:
<?
// set database info
$hostname ="localhost";
$mysql_login ="username";
$mysql_password ="password";
$database ="database";
// connect to mysql server
if (!($db = mysql_connect("$hostname", "$mysql_login" , "$mysql_password"))) {
print("Can't connect to database.");
} else {
// select your database
if (!(mysql_select_db("$database",$db))) {
print("Can't connect to table.");
}
}
// example to insert a record
$result = mysql_query("insert into user (username,password) values('sde','mypass');
// insert another record
$result = mysql_query("insert into user (username,password) values('davy','hispass');
// update sde's pass
$result = mysql_query("update user set password='newpass' where username='sde'");
// select and print all users
$result = mysql_query("select * from user");
while($row = mysql_fetch_array($result)){
echo "userid: ".$row['userid']." username: ".$row['username']."<br>\n";
}
// delete sde
$result = mysql_query("delete from user where username='sde'");
mysql_close();
?>
__________________
Mike
|
|
|
08-18-2004, 02:17 PM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
what i like to do is cut out the top connection section and put it into a file of its own called "connect.php" .. then it makes it easy to include that connection script into any pages on my website.
PHP Code:
<?
include("includes/connect.php");
// saves code, the connection is now open
// and i can start my queries
$result = mysql_query("select * from user");
// .. ...
mysql_close();
?>
__________________
Mike
|
|
|
08-18-2004, 02:43 PM
|
#5 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
I don't even know how to open MySQL. I'm starting to this it isn't an application such as Access. Command line..?
This is all a bit advanced still! Is the only way to create a table through the php coding itself? Can I not enter the fields into a GUI?
SOrry but I feel such a fool after learning so much about coding syntax (loosely around C :p )
When I understand how to get started, I ask that this topic not get closed but completely deleted because it is rather embaressing.
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
08-18-2004, 02:59 PM
|
#6 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
**** edited, bad info see next post. ****
__________________
Mike
Last edited by sde; 08-18-2004 at 03:22 PM.
|
|
|
08-18-2004, 03:06 PM
|
#7 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
http://codenewbie.com/forum/t2211.html
actually, look at the last post there .. i may be wrong with how to login for the first time, but that is how i've always done it in the past. i'm going to test it out.
bdl also posted some other good links for mysql down there.
you should always use a password, .. but the first time you use mysql as root, it doesn't require a password. you could just login with:
Code:
cd c:\mysql\bin
mysql -uroot
mysql>
then you can use the following code to reset root's password:
Code:
mysql> set password = password('mypassword');
i'm just giving this method because i couldn't get the c:\mysql\mysqladmin suggestion to work for me.
__________________
Mike
Last edited by sde; 08-18-2004 at 03:26 PM.
|
|
|
08-18-2004, 03:33 PM
|
#8 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
It says the MyODBC driver 3.51 is not found. I'm going to download that now, but:
I started typing in but for some obscure reason, it won't print the backslash character. it works fine for example here "\" but in my command prompt window.
This is extremely frustrating!!
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
08-18-2004, 03:41 PM
|
#9 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
err .. you shouldn't need myodbc. that is weird.
if it won't print backslash, then just do this:
__________________
Mike
|
|
|
08-18-2004, 03:46 PM
|
#10 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
See I thought that with not having to put the backslashes in but the prompt just starts again as it was before as C:\WINDOWS\
I am this close to giving up. I think my computer is buggered. I'm running Windows 98 on a laptop that if I tried doing anything with half CPU-intensive then I could cook breakfast on the keyboard!
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
08-18-2004, 03:54 PM
|
#11 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,166
|
Trust me, the command line is your friend. Using Windows 98 command line, you might not believe me but one of these days you're going to lean Linux (or BSD), and then you'll understand why we all make fun of Microsoft.
|
|
|
08-19-2004, 11:01 AM
|
#12 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
I'm gonna cry soon. I've had no many visions and dreams of where all of this could take me and the only thing stoppin me is that damn \black slash key it's drivin me nuts i can't get this piece of **** to work!! :'(
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
08-19-2004, 11:42 AM
|
#13 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,166
|
Most laptops let you plug in a seperate keyboard. I'd suggest you do that.
|
|
|
08-19-2004, 06:45 PM
|
#14 (permalink)
|
|
PHP Pilgrim
Join Date: Aug 2004
Location: London
Posts: 170
|
it's not a physical problem with the keyboard, look:
Code:
\\\\\\\\\\\ \ \ \ \ back slaaaaaaash \\\ and \\\\ as well as /// // / /
It just won't print in the command prompt!!
__________________
Davy - Programming since 1998 [CV]
Currently working on: n/a
Status: n/a
|
|
|
08-19-2004, 07:41 PM
|
#15 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,505
|
ok ok, wait a minute here .. take a deep breath .. i'm a bit confused .. tell me .. what were the results of my suggestion above?
start->run -> cmd enter
this should eliminate the need to use back slashes.
__________________
Mike
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 10:05 PM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|