nick@Vaxis:~$ ssh artemis Linux artemis 4.19.0-18-amd64 #1 SMP Debian 4.19.208-1 (2021-09-29) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Wed Apr 12 10:48:16 2023 from 136.168.36.197 nick@artemis:~$ cd public_html/3420/examples/ nick@artemis:~/public_html/3420/examples$ php hellodb.php PHP Parse error: syntax error, unexpected 'if' (T_IF) in /home/fac/nick/public_html/3420/examples/hellodb.php on line 90 nick@artemis:~/public_html/3420/examples$ php hellodb.php MariaDB + PHP essentials

MariaDB + PHP essentials

1 hey
2 how's
3 it
4 goin?
5 buddy
6 nice
nick@artemis:~/public_html/3420/examples$ mysql hellodb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A BWelcome to the MariaDB monitor. Commands end with ; or \g. BBYour MariaDB connection id is 98 Server version: 10.3.38-MariaDB-0+deb10u1 Debian 10 BBCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. BBType 'help;' or '\h' for help. Type '\c' to clear the current input statement. BMariaDB [hellodb]> show tables; +-------------------+ | Tables_in_hellodb | +-------------------+ | hello | | hello_data | +-------------------+ B2 rows in set (0.000 sec) BB BMariaDB [hellodb]> show create table hello_data; +------------+----------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ | View | Create View | character_set_client | collation_connection | +------------+----------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ | hello_data | CREATE ALGORITHM=UNDEFINED DEFINER=`nick`@`localhost` SQL SECURITY DEFINER VIEW `hello_data` AS select `hello`.`data` AS `data` from `hello` | utf8mb4 | utf8mb4_general_ci | +------------+----------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+ B1 row in set (0.000 sec) BB BMariaDB [hellodb]> [1]+ Stopped mysql hellodb nick@artemis:~/public_html/3420/examples$ ls -l total 24 -rw-r--r-- 1 nick nick 439 Nov 19 2021 demo_api.php -rw-r--r-- 1 nick nick 1019 Mar 11 2022 enums.php -rw-r--r-- 1 nick nick 392 Nov 9 13:33 example.php -rw-r--r-- 1 nick nick 2726 Apr 12 13:22 hellodb.php -rw-r--r-- 1 nick nick 1833 Apr 19 2022 mail_verify.php -rw-r--r-- 1 nick nick 851 Nov 29 2021 test_date.php nick@artemis:~/public_html/3420/examples$ cd .. nick@artemis:~/public_html/3420$ ls -l total 36 lrwxrwxrwx 1 nick nick 23 Jan 16 20:45 asciinema-player.css -> ../asciinema-player.css lrwxrwxrwx 1 nick nick 26 Jan 16 20:45 asciinema-player.min.js -> ../asciinema-player.min.js drwxr-xr-x 2 nick nick 4096 Mar 29 14:07 casts drwxr-xr-x 2 nick nick 4096 Apr 22 2022 chatroom drwxr-xr-x 2 nick nick 4096 Mar 30 13:48 company drwxr-xr-x 2 nick nick 4096 Mar 8 14:15 company_query drwxr-xr-x 2 nick nick 4096 Oct 19 14:13 division drwxr-xr-x 2 nick nick 4096 Mar 9 11:02 examples drwxr-xr-x 3 nick nick 4096 Mar 21 16:04 lab6 drwx------ 2 nick nick 4096 Feb 27 15:56 lab8 drwx------ 2 nick nick 4096 Mar 9 11:01 old nick@artemis:~/public_html/3420$ chmod 7555lab88 nick@artemis:~/public_html/3420$ cd lab8 nick@artemis:~/public_html/3420/lab8$ ls -l total 48 -rw-r--r-- 1 nick nick 2660 Nov 17 13:21 config.php -rw-r--r-- 1 nick nick 13972 Nov 17 13:05 FormBuilder.php -rw-r--r-- 1 nick nick 5251 Nov 17 13:05 index.mysqli.php -rw-r--r-- 1 nick nick 5478 Nov 17 14:05 index.pdo.php -rw-r--r-- 1 nick nick 451 Nov 17 13:05 index.php -rw-r--r-- 1 nick nick 208 Nov 17 13:05 style.css -rw-r--r-- 1 nick nick 689 Nov 17 13:05 tablemaker.php nick@artemis:~/public_html/3420/lab8$ cd nick@artemis:~$ ls -l total 120 drwxr-xr-x 9 nick nick 4096 Mar 30 13:03 3420 drwxr-xr-x 14 nick nick 4096 Mar 20 15:18 4420 -rw-r--r-- 1 nick nick 24425 Mar 23 13:44 companys23_2023-03-23-13-44.dump.sql -rw-r--r-- 1 nick nick 24425 Mar 23 13:43 companys23.dump.sql -rw-r--r-- 1 nick nick 24425 Mar 23 13:43 companys23_withdata.dump.sql drwx------ 2 nick nick 4096 Sep 1 2022 git_setup drwx------ 6 nick nick 4096 Oct 19 22:14 misc drwx------ 2 nick nick 4096 Dec 12 22:15 old drwx------ 3 nick nick 4096 Mar 6 13:07 prev drwxr-xr-x 2 nick nick 4096 Apr 10 22:48 public drwxr-xr-x 12 nick nick 4096 Apr 10 12:52 public_html drwx------ 3 nick nick 4096 May 10 2022 repos drwxr-xr-x 4 nick nick 4096 Feb 17 12:48 sqlite_json_demo drwx------ 5 nick nick 4096 Apr 10 12:50 src drwx------ 6 nick nick 4096 Apr 11 23:02 tmp nick@artemis:~$ php -a Interactive mode enabled php > function get_pdo_connection() { $conn; php { static $conn; php { php { if (!isset($conn)) { php { try { php { // Make persistent connection php { $options = array( php ( PDO::ATTR_PERSISTENT => true php ( ); php { php { $conn = new PDO( php ( "mysql:host=localhost;dbname=hellodb", // change dbname dbpassword", php ( "hellodbuser", // change username php ( "hellodbpassword", // change password php ( $options); php { } php { catch (PDOException $pe) { php { echo "Error connecting: " . $pe->getMessage() . "
"; php { die(); php { } to connect to database
"; php { die() php { } php { php { if ($conn === false) { php { echo "Unable to connect to database
"; php { die(); php { } php { php { return $conn; php { php { php { } php > php > $db = get_pdo_connection(); php > print_r($db); PDO Object ( ) php > echo $db; PHP Recoverable fatal error: Object of class PDO could not be converted to string in php shell code on line 1 php > $query = $db->prepare("SELECT * FROM hello"); ($query);nt_4 PDOStatement Object ( [queryString] => SELECT * FROM hello ) php > echo $query->execute(); 1 print_r($query);cute(); PDOStatement Object ( [queryString] => SELECT * FROM hello ) php > $rows = $query->fetchAll(PDO::FETCH_ASSOC); php > print_r($rows); Array ( [0] => Array ( [id] => 1 [data] => hey ) [1] => Array ( [id] => 2 [data] => how's ) [2] => Array ( [id] => 3 [data] => it ) [3] => Array ( [id] => 4 [data] => goin? ) [4] => Array ( [id] => 5 [data] => buddy ) [5] => Array ( [id] => 6 [data] => nice ) [6] => Array ( [id] => 46 [data] => sweet ) ) $rows;$ PHP Notice: Array to string conversion in php shell code on line 1 Array ];ho>$rows; PHP Notice: Array to string conversion in php shell code on line 1 Array ];ho>$rows[0]; 1 a'];>$rows[0]['id']; hey ($rowsfase$row) { ;.i'\n';h' 'r.w$row['data'\ php { } 1 hey\n2 how's\n3 it\n4 goin?\n5 buddy\n6 nice\n46 sweet\n php > exit nick@artemis:~$ mysql hellodb Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A BWelcome to the MariaDB monitor. Commands end with ; or \g. BBYour MariaDB connection id is 119 Server version: 10.3.38-MariaDB-0+deb10u1 Debian 10 BBCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. BBType 'help;' or '\h' for help. Type '\c' to clear the current input statement. BMariaDB [hellodb]> select * from hello; +----+-------------------------------------------------------------------------------------+ | id | data | +----+-------------------------------------------------------------------------------------+ | 1 | hey | | 2 | how's | | 3 | it | | 4 | goin? | | 5 | buddy | | 6 | nice | | 46 | sweet | | 47 | awww yeah | | 48 | https://cs.csub.edu/~nick/2680/assets/images/catman.jpg | | 49 | <img src="https://cs.csub.edu/~nick/2680/assets/images/catman.jpg"> | | 50 | | +----+-------------------------------------------------------------------------------------+ B11 rows in set (0.000 sec) BB BMariaDB [hellodb]> select * from hello; +----+-------------------------------------------------------------------------------------+ | id | data | +----+-------------------------------------------------------------------------------------+ | 1 | hey | | 2 | how's | | 3 | it | | 4 | goin? | | 5 | buddy | | 6 | nice | | 46 | sweet | | 47 | awww yeah | | 48 | https://cs.csub.edu/~nick/2680/assets/images/catman.jpg | | 49 | <img src="https://cs.csub.edu/~nick/2680/assets/images/catman.jpg"> | | 50 | | | 51 | buddy cat banjo | +----+-------------------------------------------------------------------------------------+ B12 rows in set (0.000 sec) BB BMariaDB [hellodb]> exit BBye Bnick@artemis:~$ exit logout There are stopped jobs. nick@artemis:~$ exit logout Connection to artemis.cs.csub.edu closed. nick@Vaxis:~$ exit exit