The following are examples of how to get started on a database of registrations, called registrations.
mysqladmin -u root -p create registrations
mysql -u root -p
grant all privileges on registrations.* to 'registrations'@'localhost' identified by 'somepassword'; flush privileges;
show databases;
use registrations;
show tables;
CREATE TABLE registrations ( id int(11) NOT NULL auto_increment, name varchar(255), email varchar(255), address text, PRIMARY KEY (id) ) TYPE=MyISAM;
DESC registrations;
DROP TABLE registrations;
INSERT INTO registrations SET name='Andrew McDonough', email='andrew@andrew.com', address='1 High Street';
SELECT * FROM registrations; SELECT id,name FROM registrations; SELECT id,name FROM registrations where id=1; SELECT * FROM registrations where name like '%ndrew%';
To connect to MySQL from PHP, you will need to connect to the database and get a database handle. I tend to assign this to the variable $dbh
$dbh = @mysql_pconnect(DB_HOST, DB_USER, DB_PASS);
@mysql_select_db(DB_NAME,$dbh);
$query = "INSERT INTO registrations SET name='Andrew', email='andrew@andrew.com', address='1 South Street'"; $result = @mysql_query($query,$dbh);
$query = "SELECT * FROM registrations WHERE id='1'"; $result = @mysql_query($query,$dbh); $record = @mysql_fetch_array($result);
$query = "SELECT * FROM registrations";
$result=@mysql_query($query,$dbh);
$result = array();
while($row=@mysql_fetch_array($result)){
array_push($result,$row);
}