implemented db-test assignment
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "violet/db-start",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Violet\\DbStart\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Joshua Ashton",
|
||||||
|
"email": "joshuatashton+dev@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"vlucas/phpdotenv": "^5.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||||
|
$dotenv->safeLoad();
|
||||||
|
$db_pass = $_ENV['DATABASE_PASSWORD'];
|
||||||
|
|
||||||
|
// Make some constants
|
||||||
|
if ($_SERVER['HTTP_HOST'] == 'localhost') {
|
||||||
|
define('HOST', 'localhost');
|
||||||
|
define('USER', 'root');
|
||||||
|
define('PASS', $db_pass);
|
||||||
|
define('DB', 'palindromes');
|
||||||
|
} else {
|
||||||
|
define('HOST', 'cs2440.joshashton.dev');
|
||||||
|
define('USER', 'root');
|
||||||
|
define('PASS', $db_pass);
|
||||||
|
define('DB', 'palindromes');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect to the DB
|
||||||
|
$conn = mysqli_connect(HOST, USER, PASS, DB);
|
||||||
|
|
||||||
|
// Write a DB query
|
||||||
|
$sql = 'SELECT * FROM palindrome;';
|
||||||
|
|
||||||
|
// Run DB query
|
||||||
|
$results = mysqli_query($conn, $sql);
|
||||||
|
|
||||||
|
// Loop through data
|
||||||
|
while ($row = mysqli_fetch_array($results, MYSQLI_ASSOC)) {
|
||||||
|
echo $row['phrase'] . '<br>';
|
||||||
|
};
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-------------------------- copy and paste to your local mysql server -------------------------------
|
||||||
|
drop database if exists palindromes;
|
||||||
|
create database palindromes;
|
||||||
|
use palindromes;
|
||||||
|
create table palindrome (id int auto_increment primary key, phrase varchar(255));
|
||||||
|
insert into palindrome (phrase) values ('race car'), ('bob'), ('senile felines'), ('stack cats');
|
||||||
|
select * from palindrome;
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------- copy and paste to your remote server ----------------------------------
|
||||||
|
create table palindrome (id int auto_increment primary key, phrase varchar(255));
|
||||||
|
insert into palindrome (phrase) values ('race car'), ('bob'), ('senile felines'), ('stack cats');
|
||||||
|
select * from palindrome;
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"name": "violet/db-start",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Violet\\DbStart\\": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Joshua Ashton",
|
||||||
|
"email": "joshuatashton+dev@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"vlucas/phpdotenv": "^5.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
require_once 'vendor/autoload.php';
|
||||||
|
|
||||||
|
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
|
||||||
|
$dotenv->safeLoad();
|
||||||
|
$db_pass = $_ENV['DATABASE_PASSWORD'];
|
||||||
|
$ip_addr = $_ENV['IP_ADDRESS'];
|
||||||
|
|
||||||
|
// Make some constants
|
||||||
|
<<<<<<< HEAD:db-test/index.php
|
||||||
|
if ($_SERVER['HTTP_HOST'] == 'localhost') {
|
||||||
|
define('HOST', 'localhost');
|
||||||
|
define('USER', 'root');
|
||||||
|
define('PASS', $db_pass);
|
||||||
|
define('DB', 'palindromes');
|
||||||
|
} else {
|
||||||
|
define('HOST', $ip_addr);
|
||||||
|
define('USER', 'root');
|
||||||
|
define('PASS', $db_pass);
|
||||||
|
define('DB', 'palindromes');
|
||||||
|
}
|
||||||
|
=======
|
||||||
|
define('HOST', '173.255.248.228');
|
||||||
|
define('USER', 'root');
|
||||||
|
define('PASS', $db_pass);
|
||||||
|
define('DB', 'palindromes');
|
||||||
|
>>>>>>> b805261 (localhost and server configuration are the same.):db-start/index.php
|
||||||
|
|
||||||
|
// Connect to the DB
|
||||||
|
$conn = mysqli_connect(HOST, USER, PASS, DB);
|
||||||
|
|
||||||
|
// Write a DB query
|
||||||
|
$sql = 'SELECT * FROM palindrome;';
|
||||||
|
|
||||||
|
// Run DB query
|
||||||
|
$results = mysqli_query($conn, $sql);
|
||||||
|
|
||||||
|
// Loop through data
|
||||||
|
while ($row = mysqli_fetch_array($results, MYSQLI_ASSOC)) {
|
||||||
|
echo $row['phrase'] . '<br>';
|
||||||
|
};
|
||||||
|
?>
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-------------------------- copy and paste to your local mysql server -------------------------------
|
||||||
|
drop database if exists palindromes;
|
||||||
|
create database palindromes;
|
||||||
|
use palindromes;
|
||||||
|
create table palindrome (id int auto_increment primary key, phrase varchar(255));
|
||||||
|
insert into palindrome (phrase) values ('race car'), ('bob'), ('senile felines'), ('stack cats');
|
||||||
|
select * from palindrome;
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
---------------------------- copy and paste to your remote server ----------------------------------
|
||||||
|
create table palindrome (id int auto_increment primary key, phrase varchar(255));
|
||||||
|
insert into palindrome (phrase) values ('race car'), ('bob'), ('senile felines'), ('stack cats');
|
||||||
|
select * from palindrome;
|
||||||
|
----------------------------------------------------------------------------------------------------
|
||||||
Reference in New Issue
Block a user