PHP database access simple example

I have the following mysql query in php:

<?php
$con=mysqli_connect("localhost","root","password", "my_db");
//Check connection
if (mysqli_connect_errno()) {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$query = "SELECT Balance FROM my_table ORDER BY ID DESC LIMIT 1";
$result = mysqli_query($con, $query);

echo $result;
?>

The echo $result does not work and I get a catchable fatal error that mysqli_query cannot be converted into string.

How do I echo my query result?

I believe that is because result is an object and it is expecting a string. Try looking into the fetch command. I believe it would go something like

while($row = mysql_fetch_assoc($result)){
      $stringTest = $row['balance'];
      echo $stringTest;
}

Something like that!

from here

Ogni lingua apre mondi diversi

Benjamin Lee Whorf

Le forme verbali sono legate alla forma di un tempo.

La vita è un eterno presente.

Influiamo nel mondo che ci circonda con azioni amorevoli.

L’amore è alla base del rapporto con mondo.

Siamo eterni perche l’uomo ha saputo pensare all’eternità e all’infinito.

Prima viene la lingua  e poi la percezione delle cose.

Noi vediamo il mondo in modo che la nostra struttura linguistica ci impone.

 

 

Useful Linux commands

from here

# 1. redo last command but as root
sudo !!

# 2. open an editor to run a command
ctrl+x+e

# 3. create a super fast ram disk
mkdir -p /mnt/ram
mount -t tmpfs tmpfs /mnt/ram -o size=8192M

# 4. don't add command to history (note the leading space)
 ls -l

# 5. fix a really long command that you messed up
fc

# 6. tunnel with ssh (local port 3337 -> remote host's 127.0.0.1 on port 6379)
ssh -L 3337:127.0.0.1:6379 root@emkc.org -N

# 7. quickly create folders
mkdir -p folder/{sub1,sub2}/{sub1,sub2,sub3}

# 8. intercept stdout and log to file
cat file | tee -a log | cat > /dev/null

# bonus: exit terminal but leave all processes running
disown -a && exit

# A. Delete all emails from bash
cat /dev/null > /var/spool/mail/root

# 11. Show PID program over port 5432
netstat -vanp tcp | grep 5432

# 12. Show PID program over port 5432
lsof -i tcp:5432

# 13. Stop postgres database on mac.sarch data folder
su postgres
/Library/PostgreSQL/9.5/bin/pg_ctl -D  /Library/PostgreSQL/9.5/data stop

Some Docker commands

Create an image linux centos from docker repository : docker run -it centos

and run into a container

docker run -i -t centos

OR

create your custom centos image like this:

  1. create a folder mkdir centos1, and go inside cd centos1
  2. download the image from here into the folder centos1
  3. create the file Dockerfile into the folder centos1

FROM scratch
ADD CentOS-7-20140625-x86_64-docker_01.img.tar.xz /
LABEL name=”CentOS Base Image” \
vendor=”CentOS” \
license=”GPLv2″ \
build-date=”20190426″
CMD [“/bin/bash”]

4. run this command into the folder centos1 : docker build -t name_of_image .

5. run the command for view list of your images : docker images

6. run this command to enter into the image : docker run -it name_of_image

  1. To save an image to any file path or shared NFS place see the following example.Get the image id by doing:
    sudo docker images
    

    Say you have an image with id “matrix-data”.

    Save the image with id:

    sudo docker save -o /home/matrix/matrix-data.tar matrix-data
    

    Copy the image from the path to any host. Now import to your local Docker installation using:

    sudo docker load -i <path to copied image file>

Remove images

docker image ls

Copy

The output should look something like this:

REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
centos                  latest              75835a67d134        7 days ago          200MB
ubuntu                  latest              2a4cca5ac898        2 months ago        111MB
linuxize/fedora         latest              a45d6dca3361        3 months ago        311MB
java                    8-jre               e44d62cf8862        3 months ago        311MB

Copy

Once you’ve located the images you want to remove, pass their IMAGE ID to the docker image rm command. For example to remove the first two images listed in the output above run:

docker image rm 75835a67d134 2a4cca5ac898

Copy

If you get an error similar to the following, it means that the image is used by an existing container. To remove the image you will have to remove the container first.

To remove one or more Docker images use the docker container rmcommand followed by the ID of the containers you want to remove.

You can get a list of all active and inactive containers by passing the -a flag to the docker container ls command:

docker container ls -a

Copy

The output should look something like this:

CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS                      PORTS               NAMES
cc3f2ff51cab        centos                  "/bin/bash"              2 months ago        Created                                         competent_nightingale
cd20b396a061        solita/ubuntu-systemd   "/bin/bash -c 'exec …"   2 months ago        Exited (137) 2 months ago                       systemd
fb62432cf3c1        ubuntu                  "/bin/bash"              3 months ago        Exited (130) 3 months ago                       jolly_mirzakhani

Copy

Once you know the CONTAINER ID of the containers you want to delete, pass it to the docker container rm command. For example to remove the first two containers listed in the output above run:

docker container rm cc3f2ff51cab cd20b396a061

Copy

If you get an error similar to the following, it means that the container is running. You’ll need to stop the container before removing it.

Regular Expression rules

Syntax

The syntax for the REGEXP_SUBSTR function in Oracle is:

REGEXP_SUBSTR( string, pattern [, start_position [, nth_appearance [, match_parameter [, sub_expression ] ] ] ] )

Parameters or Arguments

string
The string to search. It can be CHAR, VARCHAR2, NCHAR, NVARCHAR2, CLOB, or NCLOB.
pattern
The regular expression matching information. It can be a combination of the following:

Value Description
^ Matches the beginning of a string. If used with a match_parameter of ‘m’, it matches the start of a line anywhere within expression.
$ Matches the end of a string. If used with a match_parameter of ‘m’, it matches the end of a line anywhere within expression.
* Matches zero or more occurrences.
+ Matches one or more occurrences.
? Matches zero or one occurrence.
. Matches any character except NULL.
| Used like an “OR” to specify more than one alternative.
[ ] Used to specify a matching list where you are trying to match any one of the characters in the list.
[^ ] Used to specify a nonmatching list where you are trying to match any character except for the ones in the list.
( ) Used to group expressions as a subexpression.
{m} Matches m times.
{m,} Matches at least m times.
{m,n} Matches at least m times, but no more than n times.
\n n is a number between 1 and 9. Matches the nth subexpression found within ( ) before encountering \n.
[..] Matches one collation element that can be more than one character.
[::] Matches character classes.
[==] Matches equivalence classes.
\d Matches a digit character.
\D Matches a nondigit character.
\w Matches a word character.
\W Matches a nonword character.
\s Matches a whitespace character.
\S matches a non-whitespace character.
\A Matches the beginning of a string or matches at the end of a string before a newline character.
\Z Matches at the end of a string.
*? Matches the preceding pattern zero or more occurrences.
+? Matches the preceding pattern one or more occurrences.
?? Matches the preceding pattern zero or one occurrence.
{n}? Matches the preceding pattern n times.
{n,}? Matches the preceding pattern at least n times.
{n,m}? Matches the preceding pattern at least n times, but not more than m times.
start_position
Optional. It is the position in string where the search will start. If omitted, it defaults to 1 which is the first position in the string.
nth_appearance
Optional. It is the nth appearance of pattern in string. If omitted, it defaults to 1 which is the first appearance of pattern in string.
match_parameter
Optional. It allows you to modify the matching behavior for the REGEXP_SUBSTR function. It can be a combination of the following:

Value Description
‘c’ Perform case-sensitive matching.
‘i’ Perform case-insensitive matching.
‘n’ Allows the period character (.) to match the newline character. By default, the period is a wildcard.
‘m’ expression is assumed to have multiple lines, where ^ is the start of a line and $ is the end of a line, regardless of the position of those characters in expression. By default, expression is assumed to be a single line.
‘x’ Whitespace characters are ignored. By default, whitespace characters are matched like any other character.
subexpression
Optional. This is used when pattern has subexpressions and you wish to indicate which subexpression in pattern is the target. It is an integervalue from 0 to 9 indicating the subexpression to match on in pattern.

Returns

The REGEXP_SUBSTR function returns a string value.
If the REGEXP_SUBSTR function does not find any occurrence of pattern, it will return NULL.

Note

  • If there are conflicting values provided for match_parameter, the REGEXP_SUBSTR function will use the last value.
  • If you omit the match_behavior parameter, the REGEXP_SUBSTR function will use the NLS_SORT parameter to determine if it should use a case-sensitive search, it will assume that string is a single line, and assume the period character to match any character (not the newline character).
  • See also the SUBSTR function.