PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE OR REPLACE TABLE `USER` ( id MEDIUMINT NOT NULL AUTO_INCREMENT, username CHAR(30) NOT NULL, password CHAR(30) NOT NULL, PRIMARY KEY (id) ); CREATE OR REPLACE TABLE `PRODUCT` ( id MEDIUMINT NOT NULL AUTO_INCREMENT, name CHAR(30) NOT NULL, description TEXT NOT NULL, price DECIMAL(6,2), currency CHAR(3), PRIMARY KEY (id) ); CREATE OR REPLACE TABLE `CART` ( id MEDIUMINT NOT NULL AUTO_INCREMENT, product_id MEDIUMINT, user_id MEDIUMINT, PRIMARY KEY (id) ); INSERT INTO USER (username, password) VALUES ("betty_97", "betty_surfer_2024"); INSERT INTO PRODUCT ( name, description, price, currency ) VALUES ( "Surfboard", "Amzaing blue surfboard", 55.00, "EUR" ), ( "Skateboard", "Amzaing red skateboard", 15.00, "EUR" ); SELECT id from USER where username = 'betty_97' and password = 'betty_surfer_2024'
Copy Clear
Copy Format Clear
<?php use Carbon\Carbon; session_start(); function logIn( $mysqli, $userName, $password) { $query = "SELECT id from USER where username = '$userName' and password = '$password'"; printf('query: %s ',$query ); $result = $mysqli->query($query); $row = $result->fetch_object(); $userid = $row->id; if(!empty($userid)) { $_SESSION["userid"]=$userid; } } /*session is started if you don't write this line can't use $_Session global variable*/ $_SESSION["my_id"]="Olle"; $now = Carbon::now()->format('d/m/Y'); printf("Today is %s\nCurrent PHP version: %s \n\n", $now, phpversion()); ?> <ul> <li>Hello</li> </ul> <?php $query = "SELECT VERSION() as version;"; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); printf('DB version (PDO): %s ' . PHP_EOL, $row['version']); // Run query using mysqli $result = $mysqli->query($query); $version = $result->fetch_object(); printf('DB version (mysqli): %s ' . PHP_EOL, $version->version); // Select using Laravel $version = $db::select($query); printf('DB version (Laravel Query Builder): %s ' . PHP_EOL, $version[0]->version); $query = "SELECT * from PRODUCT;"; $stmt = $pdo->prepare($query); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); printf('DB version (PDO): %s ' . PHP_EOL, $row['name']); printf('session variable userid: %s ' . PHP_EOL, $_SESSION["userid"]); logIn( $mysqli,'betty_98','betty_surfer_2024') printf('session variable userid after login: %s ' . PHP_EOL, $_SESSION["userid"]); ?>
Show:  
Copy Clear