PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE t1 ( created_at DATE ) ; INSERT INTO t1 VALUES ('2023-02-03'), ('2023-02-25'); CREATE TABLE t2 ( created_at DATE ) PARTITION BY RANGE (DAYOFMONTH(created_at)) ( PARTITION p1 VALUES LESS THAN (16), PARTITION p2 VALUES LESS THAN MAXVALUE ); INSERT INTO t2 VALUES ('2023-02-03'), ('2023-02-25');
Copy Clear
Copy Format Clear
<?php $tables = ['t1', 't2']; $sql_statements = [ 'SELECT * FROM [TABLE] WHERE created_at IN (?, ?)', 'SELECT * FROM [TABLE] WHERE (created_at = ? OR created_at = ?)' ]; foreach ($tables as $table) { foreach ($sql_statements as $id => $sql) { $stmt = $mysqli->prepare(str_replace('[TABLE]', $table, $sql)); $stmt->execute(['2023-02-03', '2023-02-25']); $result = $stmt->get_result(); echo 'Table: '.$table.'; Statement: '.$id.'; Num rows: '.$result->num_rows."\n"; } echo "\n"; }
Show:  
Copy Clear