Web Programming - Week 7 Flashcards

1
Q

PHP connect to MySQL

A

$mysqli = new mysqli(“localhost”,”my_user”,”my_password”,”my_db”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to check if PHP’s connection to MySQL has failed

A

if (!$conn) {
die(“Connection failed: “ . mysqli_connect_error());
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create a select query

A

SELECT column_name(s) FROM table_name
OR
SELECT * FROM table_name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to execute a query

A

$result = mysql_query($conn, $sql);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to get data from a query

A

while ($row = mysqli_fetch_array($result)){

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Convert PHP to JSON

A

$alldata = array()
while ($row = mysqli_fetch_array($result, MYSQLI,ASSOC)){
$alldata[] =$row;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to close an opened database

A

mysqli_close($conn);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Extract data from database

A

SELECT, FROM, WHERE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is WHERE used for

A

To filter records

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

WHERE operators

A

AND/OR/NOT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the LIKE operator used for

A

To search for a specified pattern in a where clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the COUNT function used for

A

To count the number of rows that matches a specific criterion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Useful maths functions

A

AVG, Sum, MAX, MIN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is ORDER BY used for

A

To sort the result set in ascending or descending order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is JOIN used for

A

To combine rows from two or more tables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the different types of JOIN

A

INNER, LEFT, RIGHT, FULL OUTER

17
Q

What is GROUP BY used for

A

Grouping rows that have the same values

18
Q

Convert MySQL date format YYYY-MM-DD to PHP d/m/Y

A
$mysql_date = "2021-03-15";
$convertedDate = date_format(date_create($mysql_date), "d/m/Y");
19
Q

Convert PHP date format d/m/Y to MySQL date format YYYY-MM-DD

A
$date = "15/03/2021";
$date1 = str_replace("/", "-", $date);
$convertedDate = date_format(date_create($date1), "Y-m-d";