###MySQL Stuff
log in as root user: mysql -u root -p
(this will then prompt you for a password)
note: if running a command in the mysql prompt produces a -> this probably means that we have failed to insert a semicolon at the end of the line.
show databases;
create database <database-name>;
use <database-name>;
show tables;
create table <table-name> (id integer PRIMARY KEY AUTO_INCREMENT, description text NOT NULL, completed boolean NOT NULL);
(basic formatting here is column_name type modifiers, column_name type modifiers, etc)
describe <table-name>;
drop table <table-name>;
insert into <table-name> (<columnA>, <columnB>) values('Go to the store', false);
select * from <table-name>;
select * from <table-name> where id = 1;
all of these things can be done from a GUI program such as Sequel Pro
###PHP stuff that might be related to MySQL
- we can start up a PHP server by typing
php -S localhost:4000
(any port) - we can use an existing PHP class to fetch data from a MySQL database: PDO (PHP Data Objects)
//when we are manually connecting to PDO, we want to wrap it in a try/catch block
try {
$pdo = new PDO('mysql:host=127.0.0.1;dbname=<database-name>', '<username>', '<password>');
} catch (PDOException $e) {
die('Could not connect.');
}