Difference between revisions of "PHP/MySQL"

From dbawiki
Jump to: navigation, search
Line 23: Line 23:
 
<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
 
<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
 
<button type="button" onclick="?run=true">Click Me!</button>
 
<button type="button" onclick="?run=true">Click Me!</button>
 +
</pre>
 +
===Start MySQL at boot time===
 +
To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system
 +
===Set a root password after installing MySQL===
 +
<pre>
 +
/usr/bin/mysqladmin -u root password 'new-password'
 +
/usr/bin/mysqladmin -u root -h <hostname> password 'new-password'
 +
</pre>
 +
Alternatively you can run:
 +
<pre>
 +
/usr/bin/mysql_secure_installation
 +
</pre>
 +
which will also give you the option of removing the test databases and anonymous user created by default.  This is strongly recommended for production servers.
 +
===Start the MySQL daemon===
 +
<pre>
 +
cd /usr ; /usr/bin/mysqld_safe &
 +
</pre>
 +
You can test the MySQL daemon with:
 +
<pre>
 +
cd /usr/mysql-test ; perl mysql-test-run.pl
 
</pre>
 
</pre>

Revision as of 00:20, 31 January 2015

Excellent tutorial on Object Oriented PHP

www.killerphp.com

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()

$dbPreparedStatement = $db->prepare('INSERT INTO table (postId, htmlcontent) VALUES (:postid, :htmlcontent)');
$dbPreparedStatement->bindParam(':postid', $userId, PDO::PARAM_INT);
$dbPreparedStatement->bindParam(':htmlcontent', $yourHtmlData, PDO::PARAM_STR);
$dbPreparedStatement->execute();

Fill your boots on PDO here

CSV tables - equivalent of External tables in Oracle

Run a shell script with an html button

<?php
if ($_GET['run']) {
  # This code will run if ?run=true is set.
  exec("/path/to/name.sh");
}
?>
<!-- This link will add ?run=true to your URL, myfilename.php?run=true -->
<button type="button" onclick="?run=true">Click Me!</button>

Start MySQL at boot time

To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system

Set a root password after installing MySQL

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h <hostname> password 'new-password'

Alternatively you can run:

/usr/bin/mysql_secure_installation

which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers.

Start the MySQL daemon

cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with:

cd /usr/mysql-test ; perl mysql-test-run.pl