Wednesday, June 24, 2015

[CheatSheet] PHP MySQL

22 Juni 2015

MYSQL

- Reset auto increment
ALTER TABLE tablename AUTO_INCREMENT = 1

- clear table
TRUNCATE TABLE tablename

- select table
SELECT * FROM table

- insert row
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

- insert multi row
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...),
       (value1, value2, value3,...),
       (value1, value2, value3,...);

PHP5

-date
date("Y-m-d");                         // 2015-10-01

-time
date("Y-m-d H:i:s");                   // 2015-10-01 17:03:18

-do while
$x = 1; 
do {
    echo "The number is: $x <br>";
    $x++;
}

while ($x <= 5);


-call db
$query = 'SELECT * FROM table';
$mysql = $conn->query($qno);
if ($mysql->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
//interesting here
    }
}

No comments:

Post a Comment