php_mysql
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| php_mysql [2018/12/08 12:49] – created 0.0.0.0 | php_mysql [2019/01/30 11:32] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | * [[https:// |
| - | + | * [[http:// | |
| - | * [[https:// | + | * [[https:// |
| - | * [[https:// | + | * [[https:// |
| - | =====Excellent tutorial on Object Oriented PHP===== | + | * [[https:// |
| + | ==== Excellent tutorial on Object Oriented PHP ==== | ||
| [[http:// | [[http:// | ||
| - | =====Using prepared statements to avoid SQL injection===== | + | ==== Using prepared statements to avoid SQL injection ==== |
| Using this method of writing SQL removes the necessity of attempting to clean the input with mysql_real_escape_string() | Using this method of writing SQL removes the necessity of attempting to clean the input with mysql_real_escape_string() | ||
| - | < | + | < |
| + | $dbPreparedStatement = $db-> | ||
| + | $dbPreparedStatement-> | ||
| + | $dbPreparedStatement-> | ||
| + | $dbPreparedStatement-> | ||
| + | </ | ||
| Fill your boots on PDO [[http:// | Fill your boots on PDO [[http:// | ||
| [[CSV tables - equivalent of External tables in Oracle]] | [[CSV tables - equivalent of External tables in Oracle]] | ||
| - | =====Force user logout if session is inactive for a certain period of time===== | + | ==== Force user logout if session is inactive for a certain period of time ==== |
| As seen on [[https:// | As seen on [[https:// | ||
| - | < | + | < |
| + | // Add the following into your HEAD section | ||
| + | var timer = 0; | ||
| + | function set_interval() { | ||
| + | // the interval ' | ||
| + | timer = setInterval(" | ||
| + | // the figure ' | ||
| + | // Eg: to set it to 5 mins, calculate 5min = 5x60 = 300 sec = 300,000 millisec. | ||
| + | // So set it to 300000 | ||
| + | } | ||
| + | |||
| + | function reset_interval() { | ||
| + | //resets the timer. The timer is reset on each of the below events: | ||
| + | // 1. mousemove | ||
| + | //first step: clear the existing timer | ||
| + | |||
| + | if (timer != 0) { | ||
| + | clearInterval(timer); | ||
| + | timer = 0; | ||
| + | // second step: implement the timer again | ||
| + | timer = setInterval(" | ||
| + | // completed the reset of the timer | ||
| + | } | ||
| + | } | ||
| + | |||
| + | function auto_logout() { | ||
| + | // this function will redirect the user to the logout script | ||
| + | window.location = " | ||
| + | } | ||
| + | |||
| + | // Add the following attributes into your BODY tag | ||
| + | onload=" | ||
| + | onmousemove=" | ||
| + | onclick=" | ||
| + | onkeypress=" | ||
| + | onscroll=" | ||
| + | </ | ||
| or a " | or a " | ||
| - | < | + | < |
| + | <META HTTP-EQUIV=" | ||
| + | </ | ||
| - | =====Run a shell script with an html button===== | + | ==== Run a shell script with an html button ==== |
| - | < | + | < |
| - | =====Start MySQL at boot time===== | + | <?php |
| + | if ($_GET[[' | ||
| + | # This code will run if ?run=true is set. | ||
| + | exec("/ | ||
| + | } | ||
| + | ?> | ||
| + | <!-- This link will add ?run=true to your URL, myfilename.php? | ||
| + | <button type=" | ||
| + | </ | ||
| + | ==== Load an SQL file into a MySQL database from the command line ==== | ||
| + | mysql -u my-mysql-username -p my-database-name < name-of-sql-file.sql | ||
| + | ==== Start MySQL at boot time ==== | ||
| To start mysqld at boot time you have to copy support-files/ | To start mysqld at boot time you have to copy support-files/ | ||
| - | =====Set a root password after installing MySQL===== | + | ==== Set a root password after installing MySQL ==== |
| - | < | + | < |
| + | / | ||
| + | / | ||
| + | </ | ||
| Alternatively you can run: | Alternatively you can run: | ||
| - | < | + | < |
| + | / | ||
| + | </ | ||
| which will also give you the option of removing the test databases and anonymous user created by default. | which will also give you the option of removing the test databases and anonymous user created by default. | ||
| - | =====Start the MySQL daemon===== | + | ==== Start the MySQL daemon ==== |
| - | < | + | < |
| + | cd /usr ; / | ||
| + | </ | ||
| You can test the MySQL daemon with: | You can test the MySQL daemon with: | ||
| - | < | + | < |
| - | =====Reset a forgotten MySQL root password===== | + | cd / |
| - | * [[http:// | + | </ |
| - | * [[https:// | + | ==== Reset a forgotten MySQL root password ==== |
| - | Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.<br /> | + | * [[http:// |
| + | * [[https:// | ||
| + | Stop mysqld and restart it with the --skip-grant-tables option. This enables anyone to connect without a password and with all privileges. Because this is insecure, you might want to use --skip-grant-tables in conjunction with --skip-networking to prevent remote clients from connecting.\\ | ||
| Connect to the mysqld server with this command: | Connect to the mysqld server with this command: | ||
| - | < | + | < |
| + | shell> mysql | ||
| + | </ | ||
| Issue the following statements in the mysql client. Replace the password with the password that you want to use. | Issue the following statements in the mysql client. Replace the password with the password that you want to use. | ||
| - | < | + | < |
| - | The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.<br /> | + | mysql> UPDATE mysql.user SET Password=PASSWORD(' |
| + | mysql> FLUSH PRIVILEGES; | ||
| + | </ | ||
| + | The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.\\ | ||
| You should now be able to connect to the MySQL server as root using the new password. Stop the server, then restart it normally (without the --skip-grant-tables and --skip-networking options). | You should now be able to connect to the MySQL server as root using the new password. Stop the server, then restart it normally (without the --skip-grant-tables and --skip-networking options). | ||
| + | |||
php_mysql.1544273361.txt.gz · Last modified: 2018/12/08 12:49 by 0.0.0.0
