-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cd1d330
commit 48aeaea
Showing
64 changed files
with
912 additions
and
742 deletions.
There are no files selected for viewing
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
// Create connection | ||
$con = mysqli_connect(localhost, 'root', 'root', 'myDB'); | ||
|
||
// Check connection | ||
if (!$con) { | ||
die('Connection failed: ' . mysqli_connect_error()); | ||
} | ||
|
||
//AND OPERATOR -------------------------------------- | ||
echo '<h4>mySQL - AND operator</h4>'; | ||
$result = mysqli_query($con, "SELECT * from student WHERE course = 'mba' AND location='vellore'"); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s - %s - %s - %s - %s - %s - %s ', $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7]); | ||
printf('<br>'); | ||
} | ||
|
||
print '<hr>'; | ||
|
||
//OR OPERATOR -------------------------------------- | ||
|
||
echo '<h4>mySQL - OR operator</h4>'; | ||
$result = mysqli_query($con, "SELECT * from student WHERE course = 'PHD' OR location='OHIO' OR age='30'"); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s - %s - %s - %s - %s - %s - %s ', $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7]); | ||
printf('<br>'); | ||
} | ||
|
||
print '<hr>'; | ||
|
||
//NOT OPERATOR -------------------------------------- | ||
echo '<h4>mySQL - NOT operator</h4>'; | ||
$result = mysqli_query($con, "SELECT * from student WHERE NOT course = 'mba' AND location='vellore'"); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s - %s - %s - %s - %s - %s - %s ', $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7]); | ||
printf('<br>'); | ||
} | ||
print '<hr>'; | ||
//TWO NOT OPERATOR -------------------------------------- | ||
echo '<h4>mySQL - NOT operator - TWO TIMES</h4>'; | ||
$result = mysqli_query($con, "SELECT * from student WHERE NOT course = 'mba' AND NOT location='vellore'"); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s - %s - %s - %s - %s - %s - %s ', $row[0], $row[1], $row[2], $row[3], $row[4], $row[5], $row[6], $row[7]); | ||
printf('<br>'); | ||
} | ||
mysqli_close($conn); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
// Create connection | ||
$con = mysqli_connect(localhost, 'root', 'root', 'myDB'); | ||
|
||
// Check connection | ||
if (!$con) { | ||
die('Connection failed: ' . mysqli_connect_error()); | ||
} | ||
|
||
//BETWEEN Function -------------------------------------- | ||
echo '<h4>mySQL - BETWEEN Function </h4>'; | ||
$result = mysqli_query($con, 'SELECT RegNo, AGE from student WHERE AGE BETWEEN 20 AND 30'); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s ---- %s', $row[0], $row[1]); | ||
echo '<br>'; | ||
} | ||
|
||
print '<hr>'; | ||
|
||
//NOT BETWEEN Function -------------------------------------- | ||
echo '<h4>mySQL - NOT BETWEEN Function </h4>'; | ||
$result = mysqli_query($con, 'SELECT RegNo, AGE from student WHERE AGE NOT BETWEEN 20 AND 30'); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s ---- %s', $row[0], $row[1]); | ||
echo '<br>'; | ||
} | ||
|
||
print '<hr>'; | ||
|
||
// BETWEEN - TEXT VALUE Function -------------------------------------- | ||
echo '<h4>mySQL - BETWEEN - TEXT VALUE Function </h4>'; | ||
$result = mysqli_query($con, "SELECT RegNo, FIRSTNAME from student WHERE FIRSTNAME BETWEEN 'A' AND 'D'"); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s ---- %s', $row[0], $row[1]); | ||
echo '<br>'; | ||
} | ||
|
||
print '<hr>'; | ||
|
||
//NOT BETWEEN - TEXT VALUE Function -------------------------------------- | ||
echo '<h4>mySQL - NOT BETWEEN Function </h4>'; | ||
$result = mysqli_query($con, "SELECT RegNo, FIRSTNAME from student WHERE FIRSTNAME NOT BETWEEN 'A' AND 'P'"); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s ---- %s', $row[0], $row[1]); | ||
echo '<br>'; | ||
} | ||
|
||
print '<hr>'; | ||
|
||
//BETWEEN - DATE Function -------------------------------------- | ||
echo '<h4>mySQL - DATE BETWEEN Function </h4>'; | ||
$result = mysqli_query($con, "SELECT RegNo, FIRSTNAME from student WHERE FIRSTNAME BETWEEN '2020-01-01' AND '2021-03-31' "); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s ---- %s', $row[0], $row[1]); | ||
echo '<br>'; | ||
} | ||
|
||
print '<hr>'; | ||
|
||
mysqli_close($con); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
// Create connection | ||
$con = mysqli_connect(localhost, 'root', 'root', 'myDB'); | ||
|
||
// Check connection | ||
if (!$con) { | ||
die('Connection failed: ' . mysqli_connect_error()); | ||
} | ||
|
||
|
||
//BETWEEN with IN Function -------------------------------------- | ||
echo '<h4>mySQL - BETWEEN with IN Function </h4>'; | ||
$result = mysqli_query($con, "SELECT RegNo, AGE from student WHERE AGE BETWEEN 20 AND 30 AND COURSE IN ('MBA')"); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s ---- %s', $row[0], $row[1]); | ||
echo '<br>'; | ||
} | ||
|
||
print '<hr>'; | ||
|
||
//BETWEEN with NOT IN Function -------------------------------------- | ||
echo '<h4>mySQL - BETWEEN with NOT IN Function </h4>'; | ||
$result = mysqli_query($con, "SELECT RegNo, AGE from student WHERE AGE BETWEEN 20 AND 30 AND COURSE NOT IN ('MBA')"); | ||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s ---- %s', $row[0], $row[1]); | ||
echo '<br>'; | ||
} | ||
|
||
print '<hr>'; | ||
|
||
|
||
//BETWEEN with NOT IN Function - OR OPERATOR -------------------------------------- | ||
echo '<h4>mySQL - BETWEEN with NOT IN Function - OR OPERATOR </h4>'; | ||
|
||
$result = mysqli_query($con, "SELECT COURSE, AGE from student WHERE AGE BETWEEN 20 AND 30 OR COURSE NOT IN ('MBA')"); | ||
|
||
while ($row = mysqli_fetch_array($result, MYSQLI_NUM)) { | ||
printf('%s ---- %s', $row[0], $row[1]); | ||
echo '<br>'; | ||
} | ||
|
||
mysqli_close($con); | ||
?> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
$con = mysqli_connect("localhost", "root", "root"); | ||
if (!$con) { | ||
die("Connection failed:" . mysqli_connect_error()); | ||
} | ||
echo "Connected successfully"; | ||
mysqli_close($con); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
//Connection | ||
$con = mysqli_connect("localhost", "root", "root"); | ||
if (!$con) { | ||
die('Could not connect: ' . mysqli_connect_error()); | ||
} else { | ||
echo "Connection Connected <br>"; | ||
} | ||
|
||
//Database Selection | ||
|
||
//mysqli_select_db($con, "myDBdd"); | ||
if (mysqli_select_db($con, "myDB")) { | ||
echo "Database Selected Successfully <br>"; | ||
} else { | ||
echo "Error in Selecting the Database <br>", mysqli_errno($con); | ||
} | ||
|
||
//Table Creation | ||
|
||
$sql = "create table student (FirstName varchar(25), LastName varchar(25), Age varchar(3))"; | ||
|
||
if (!mysqli_query($con, $sql)) { | ||
die('Error: ' . mysqli_errno($con)); | ||
} | ||
echo "Table Created Successfully"; | ||
|
||
mysqli_close($con); | ||
?> |
35 changes: 35 additions & 0 deletions
35
Code/PHP MySQL - CREATE TABLE - 2 - PRIMARY KEY AND NOT NULL.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
//Connection | ||
$con = mysqli_connect('localhost', 'root', 'root'); | ||
if (!$con) { | ||
die('Could not connect: ' . mysqli_connect_error()); | ||
} else { | ||
echo 'Connection Connected <br>'; | ||
} | ||
|
||
//Database Selection | ||
|
||
//mysqli_select_db( $con, 'myDBdd' ); | ||
if (mysqli_select_db($con, 'myDB')) { | ||
echo 'Database Selected Successfully <br>'; | ||
} else { | ||
echo 'Error in Selecting the Database <br>', mysqli_errno($con); | ||
} | ||
|
||
//Table Creation | ||
|
||
$sql = "create table student ( | ||
RegNo varchar(25) NOT NULL, | ||
FirstName varchar(25), | ||
LastName varchar(25), | ||
Age varchar(3), | ||
PRIMARY KEY (RegNo) | ||
)"; | ||
|
||
if (!mysqli_query($con, $sql)) { | ||
die('Error: ' . mysqli_errno($con)); | ||
} | ||
echo 'Table Created Successfully'; | ||
|
||
mysqli_close($con); | ||
?> |
Oops, something went wrong.