to change all the directories to 755:
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
to change all the files to 644:
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
array explode ( string $delimiter , string $string [, int $limit ] )
<?php
$str = 'one|two|three|four';
// positive limit
print_r(explode('|', $str, 2));
<?php
$str = 'one|two|three|four';
// negative limit (since PHP 5.1)
print_r(explode('|', $str, -1));
<?php
$str = 'one|two|three|four';
// limit with 0 and 1 would be same
print_r(explode('|', $str, 0));
<?php
$array = array('XXX', 'TTT', '2123123');
$dash_separated = implode("-", $array);
var_dump($dash_separated);
<?php
//When using empty array it will return empty string even passed the glue
var_dump(implode('hello', array()));
<?php
//When imploding boolean values it will just return the values of true
var_dump(implode('',array(true, true, false, false, true)));
<?php
//Quite handier with sql functions with arrays
$fields = array(
'subject' => 'go green',
'message' => 'i am going to take off!'
);
$sql = 'INSERT INTO table_name';
$sql .= " VALUES (`" . implode("`,`", array_keys($fields)) . "`)";
$sql .= " ('" . implode("','", $fields) . "')";
var_dump($sql);
$userIds = array(2, 32, 55, 200, 44);
$sql2 = "SELECT * FROM table_name";
$sql2 .= " WHERE 1 AND (id=" . implode(" OR id = ", $userIds) . ")";
var_dump($sql2);
mysql> SELECT @@tx_isolation;
+-----------------+
| @@tx_isolation |
+-----------------+
| REPEATABLE-READ |
+-----------------+
mysql> SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
mysql> SELECT @@tx_isolation;
+----------------+
| @@tx_isolation |
+----------------+
| SERIALIZABLE |
+----------------+
SET TRANSACTION ISOLATION LEVEL
statement.mysql> SELECT @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 1 |
+--------------+
mysql> SET autocommit=0;
mysql> SELECT @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 0 |
+--------------+
mysql> SELECT @@autocommit;
+--------------+
| @@autocommit |
+--------------+
| 1 |
+--------------+
CREATE TABLE Test(Num INTEGER NOT NULL) engine=InnoDB;
mysql> INSERT INTO Test VALUES (1), (2), (3);
mysql> SELECT * FROM Test;
+-----+
| Num |
+-----+
| 1 |
| 2 |
| 3 |
+-----+
mysql> SET autocommit=0;
mysql> INSERT INTO Test VALUES (4), (5);
mysql> SELECT * FROM Test;
+-----+
| Num |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+-----+
mysql> ROLLBACK;
mysql> SELECT * FROM Test;
+-----+
| Num |
+-----+
| 1 |
| 2 |
| 3 |
+-----+
ROLLBACK
statement, we take them back.mysql> INSERT INTO Test VALUES (4), (5);
mysql> COMMIT;
mysql> ROLLBACK;
mysql> SELECT * FROM Test;
+-----+
| Num |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
+-----+
COMMIT
statement. Subsequent rollback statement has no effect.mysql> TRUNCATE Test;
Query OK, 0 rows affected (0.02 sec)
mysql> SELECT * FROM Test;
Empty set (0.00 sec)
mysql> START TRANSACTION;
mysql> INSERT INTO Test VALUES (1), (2);
mysql> INSERT INTO Test VALUES (3), (4);
mysql> SELECT * FROM Test;
+-----+
| Num |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
+-----+
$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 65
Server version: 5.1.41-3ubuntu12.9 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SELECT * FROM mydb.Test;
Empty set (0.00 sec)
mysql> COMMIT;
COMMIT
statement commits the data to the table. The rows are visible from both connections.mysql> START TRANSACTION;
mysql> INSERT INTO Test VALUES (5), (6);
mysql> INSERT INTO Test VALUES (7), (8);
mysql> ROLLBACK;
mysql> SELECT * FROM Test;
+-----+
| Num |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
+-----+
ROLLBACK
statement. Subsequent select from the table shows that the data was not committed to the table.grep -r hello .
CREATE TABLE task (
id INT PRIMARY KEY AUTO_INCREMENT,
subject VARCHAR(255),
description text
);
<?php
class baseDao
{
private $connection;
public function __construct() {
$this->connectToDb(DB_USER, DB_PASS, DB_HOST, DB_NAME);
}
public function connectToDb($user, $pass, $host, $database) {
$this->connection = mysql_connect($host, $user, $pass);
mysql_select_db($database, $this->connection);
}
public function fetch($value, $key = NULL)
{
if (is_null($key)) {
$key = $this->_primaryKey;
}
$sql = "SELECT * FROM {$this->_tableName} WHERE {$key} = '" . $value . "';";
$results = mysql_query($sql, $this->connection);
$rows = array();
while ($result = mysql_fetch_array($results)) {
$rows[] = $result;
}
return $rows;
}
public function update($keyedArray)
{
$sql = "UPDATE {$this->_tableName} SET ";
$updates = array();
foreach ($keyedArray as $column=>$value) {
$updates[] = "{$column}='" . $value . "'" ;
}
$sql .= implode(",", $updates);
$sql .= " where {$this->_primaryKey}='". $keyedArray[$this->_primaryKey] . "';";
mysql_query($sql, $this->connection);
}
public function save($keyedArray)
{
$sql = "INSERT INTO {$this->_tableName} ";
$updates = array();
foreach ($keyedArray as $column=>$value) {
$updates_columns[] = "{$column}";
$updates_values[] = "'" . $value . "'" ;
}
$sql .= "(";
$sql .= implode(",", $updates_columns);
$sql .= ")";
$sql .= " VALUES (";
$sql .= implode(",", $updates_values);
$sql .= ");";
if (!mysql_query($sql, $this->connection))
echo mysql_error();
}
}
<?php
//DB_USER, DB_PASS, DB_HOST, DB_NAME
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_HOST', 'localhost');
define('DB_NAME', 'blog_samples');
//include "baseDao.php";
include "taskDao.php";
$taskDao = new taskDao();
$updates=array('subject' => 'testSubjectValue', 'description' => 'testDescriptionValue');
$taskDao->save($updates);
echo "<br/>Dao pattern !<br/>";
class Product
{
protected $type = '';
protected $size = '';
protected $color = '';
protected $price = '';
public function setColor($color)
{
$this->color = $color;
}
public function setSize($size)
{
$this->size = $size;
}
public function setType($type)
{
$this->type = $type;
}
public function setPrice($price)
{
$this->price = $price;
}
function __toString()
{
$text = 'Product { ';
$text .= ":type => " . $this->type;
$text .= ", :size => " . $this->size;
$text .= ", :color => " . $this->color;
$text .= ", :price => " . $this->price;
$text .= " }";
return $text;
}
}
// our product configuration received from other functionality
$productConfigs = array(‘type’=>’shirt’, ‘size’=>’XL’, ‘color’=>’red’);
$product = new product();
$product->setType($productConfigs[‘type’]);
$product->setSize($productConfigs[‘size’]);
$product->setColor($productConfigs[‘color’]);
class ProductBuilder
{
protected $product = NULL;
protected $config = array();
public function __construct($config){
$this->product = new Product();
$this->config = $config;
}
public function build() {
$this->product->setType($this->config['type']);
$this->product->setColor($this->config['color']);
$this->product->setSize($this->config['size']);
$this->product->setPrice($this->config['price']);
}
public function getProduct() {
return $this->product;
}
}
$builder = new productBuilder($productConfigs);
$builder->build();
$product = $builder->getProduct();