GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Mar-2003, 13:24
nniehoff nniehoff is offline
Member
 
Join Date: Aug 2001
Location: US
Posts: 115
nniehoff has a spectacular aura about

[Tutorial] MySQL Basics


I know Perl, and PHP (a little), but I need to learn how to use MySQL so I was wondering if anyone knows of any good php, perl, or MySQL tutorial/reference sites?
Nick
  #2  
Old 18-Mar-2003, 17:27
Elmseeker's Avatar
Elmseeker Elmseeker is offline
Awaiting Email Confirmation
 
Join Date: Jan 2003
Posts: 87
Elmseeker is on a distinguished road
for php and php/mysql and how they work together I like Evil Walrus www.evilwalrus.com
  #3  
Old 19-Mar-2003, 04:51
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Just ask Nick and I might even write whole articles just for you
  #4  
Old 19-Mar-2003, 07:55
nniehoff nniehoff is offline
Member
 
Join Date: Aug 2001
Location: US
Posts: 115
nniehoff has a spectacular aura about
Evil Walrus is down. JdS, with all of the wonderful luck I am having I would really appreciate any help you could give me. Thanks,
Nick
  #5  
Old 19-Mar-2003, 08:07
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
MySQL is really simple, so tell us what you want to do and we will try to post some sample code here.
  #6  
Old 19-Mar-2003, 08:12
nniehoff nniehoff is offline
Member
 
Join Date: Aug 2001
Location: US
Posts: 115
nniehoff has a spectacular aura about
Well I need to learn the basics about MySQL and how it works and the neat things that it will do. I am working on a quiz/survey script. I am using a win 2k system with everything on it. I don't know if I will use Perl or PHP, or maybe both.

Nick
  #7  
Old 19-Mar-2003, 08:52
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Connecting to the MySQL database.


Here's how you could connect to a MySQL database:
PHP Code:

<?php

//  Establishing a (MySQL) database connection with PHP

//  Connecting...
$conn = mysql_connect( 'localhost', 'username', 'password' );
//  If error, halt the script...
if( !$conn ):
  echo 'Could not connect... try again later.';
  exit;
endif;

//  Which database to use?
$db = mysql_select_db( 'dbname', $conn );
//  If error, halt the script...
if( !$db ):
  echo 'Could not select the database... try again later.';
  exit;
endif;

// The rest of your PHP code...
?>


I personally would use mysql_pconnect() only if my website was on a dedicated server. If on a shared / virtual host, I would stick with mysql_connect().
  #8  
Old 19-Mar-2003, 16:49
nniehoff nniehoff is offline
Member
 
Join Date: Aug 2001
Location: US
Posts: 115
nniehoff has a spectacular aura about
So how do I make the structure of a new db?
Nick
  #9  
Old 20-Mar-2003, 02:31
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough

Create a new MySQL database table


To create a MySQL database table, listed below are some of the available options:
  1. If you have shell access, you can use the mysql client program to create and use databases - but, you don't even want to go there if you're just starting out.
  2. A 3rd party PHP script that allows you to manage your MySQL databases. e.g. www.phpmyadmin.net.
  3. Just create [gid=http://www.desilva.biz/mysql/createtbl.html]a PHP file that will create a MySQL database table for you[/gid]. e.g. like in an install.php.

Let's say you want to create a table named: members in the database named nicksdb. The structure of this fictitious table is something like this:

Code:
DATABASE: nicksdb TABLE: members id |fname |email |www ----+---------+---------------------+---------------- 1 |george |george@example.com |www.example.com 2 |saddam |saddam@example.org |www.example.org 3 |tony |tony@example.net |www.example.net

In other words, this db table will contain 4 columns. You create this table and the four columns much like you would an MS Access database table - defining the column type, size, etc...

A sample php page that would create this particular sample database table could look something like this:
PHP Code:

<?php

//  FILENAME: INSTALL.PHP
//  ---------------------

//  Establishing a (MySQL) database connection with PHP

//  Connecting...
$conn = mysql_connect( 'localhost', 'nniehoff', '0123456' );
//  If error, halt the script...
if( !$conn ):
  echo 'Could not connect... try again later.';
  exit;
endif;

//  Which database to use?
$db = mysql_select_db( 'nicksdb', $conn );
//  If error, halt the script...
if( !$db ):
  echo 'Could not select the database... try again later.';
  exit;
endif;

// Now create your table: members
echo "<p>Creating table: 'members'....</p>";
$sql = 'CREATE TABLE `members` (
        `id` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
        `fname` VARCHAR( 50 ) NOT NULL,
        `email` VARCHAR( 40 ) NOT NULL,
        `www` VARCHAR( 255 ) NOT NULL,
        PRIMARY KEY ( `id` )
       )';
mysql_query( $sql, $conn );

?>


Now when you bring up this file; install.php on your browser, it should create a table named members in the database named nicksdb!
  #10  
Old 21-Mar-2003, 10:09
nniehoff nniehoff is offline
Member
 
Join Date: Aug 2001
Location: US
Posts: 115
nniehoff has a spectacular aura about
How many tables can one db hold and how do you create relationships between them? Also "TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT" these are really cool constrainsts to put on a field in a table but what all can be used and what do they do?
Nick
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A problem Between MySQL <> phpBB mirable MySQL / PHP Forum 3 10-Sep-2003 05:31
Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More EyotaHosts Web Hosting Advertisements & Offers 0 28-Jun-2003 13:54
[Tutorial] XSL Basics Pt. III pcxgamer Web Design Forum 1 24-Apr-2003 08:04
[Tutorial] XSL Basics Pt. I pcxgamer Web Design Forum 15 22-Apr-2003 06:59
[Tutorial] XSL Basics Pt. II pcxgamer Web Design Forum 0 21-Apr-2003 07:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:55.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.