Mysql
Title | Code |
---|---|
|
1) $sql="update child set name='Aslam' where id=8"; 2) $sql="update child set roll=1 where id=7"; 3) $sql="update child set name='$name',roll='$roll' where id=$id"; |
|
table id salary bonus extra sum..? 01 500 200 300 02 100 200 400 03 500 200 300 $sql=select id,(select sum(salary),(bonus),(extra) as tblSum(Earnings)) from table_name"); |
|
ASC .......... $sql ="select * from table_name order by id ASC limit 1"; $result = mysqli_query($conn,$sql); DESC .......... $sql ="select * from table_name order by id DESC limit 1"; $result = mysqli_query($conn,$sql); ...... N:B: order by id, date, age no matter... ...... select all without last one $sql ="SELECT * FROM table ORDER BY id DESC LIMIT 13 OFFSET 1"; Or... $sql ="select *from table where id!=(select max(id) from table )"; |
|
$sql ="select id,item,code from html UNION all select id,item,code from css UNION all select id,item,code from bootstrap UNION all select id,item,code from js UNION all select id,item,code from php UNION all select id,item,code from laravel UNION all select id,item,code from mysql UNION all select id,item,code from android UNION all select id,item,code from editor UNION all select id,item,code from softwere UNION all select id,item,code from github UNION all select id,item,code from other "; $result = mysqli_query($code,$sql); Same output $type = 'code_type'; $all_item ="select *from $type where id!=(select max(id) from $type)"; $all_row_result = mysqli_query($code,$all_item); $last_item ="SELECT * FROM $type ORDER BY ID D |
|
Although VARCHAR supports the maximum size at 65535 characters the actual maximum value depends on other columns in the table and character set: Maximum row size is 65535 bytes in MySQL that shared among all columns in the table except TEXT/BLOB columns. |
|
C:\laragon\etc\apps\phpMyAdmin\templates\login\form.twig Line no : 51 change : value="{{ default_user }}" to value="root" |
|
phpmyadmin left side click "new" right side top "variables" search "sql_mode" edit & remove "ONLY_FULL_GROUP_BY," then save |
|
$hostName = "localhost"; $userName = "root"; $password = ""; $dbName = "name"; $mysqli = new mysqli($hostName, $userName, $password, $dbName); // Make sure table_1 and table_2 same column (same database) $sql = "insert table_1 SELECT * FROM table_2"; $query = mysqli_query($mysqli, $sql); if($query){ echo "Success"; }else{ echo "Fail"; } Or........... $sql = "insert offline_online2(invoice_id, status) SELECT invoice_id, status FROM offline_online where invoice_id = 'INV-0000121'"; $query = mysqli_query($mysqli, $sql); if($query){ echo "Success"; }else{ echo "Fail"; } Source: https://www.youtube.com/watch?v=epIyuRZC_q0&ab_channel=CodingShiksha |
|
NB: Same localhost server $sql = "INSERT INTO pos_test.offline_online SELECT * FROM pos_restaurant.offline_online WHERE invoice_id = 'INV-0000120'"; $query = mysqli_query($mysqli, $sql); if($query){ echo "Success"; }else{ echo "Fail"; } |
|
<?php // onlne, offline table [id, invoice_id, status] $mysqli = new mysqli($hostName, $userName, $password, $dbName); $tableName = 'offline'; $sql = "SELECT * FROM $tableName"; $query = mysqli_query($mysqli, $sql); $row = mysqli_fetch_assoc($query); $columnList = implode(', ', array_keys($row)); echo "<pre>"; var_export($columnList); echo "</pre>"; // Fatch offline row $sql = "SELECT * FROM offline WHERE status = 'pending'"; $query = mysqli_query($mysqli, $sql); while($row = mysqli_fetch_assoc($query)){ $order_id = $row['invoice_id']; $sql2 = "SELECT * FROM $tableName where invoice_id = '$order_id'"; $query2 = mysqli_query($mysqli, $sql2); $array = []; while($row3 = mysqli_fetch_assoc($query2)){ foreach($row3 as $key => $value){ $array[$key] = "'" .$value. "'"; } $valueList = implode(', ', $array); $sql3 = "INSERT INTO online ($columnList) VALUES ($valueList)"; $query3 = mysqli_query($mysqli, $sql3); echo (($query3) ? 'Success' : 'Fail'); } } ?> |
|
<?php $hostName = "localhost"; $userName = "root"; $password = "123456"; $offline = "offline"; $mysqli = new mysqli($hostName, $userName, $password, $offline); $online = "online"; $mysqli_online = new mysqli($hostName, $userName, $password, $online); $tableName = 'sd_order_list'; $sql = "SELECT * FROM $tableName"; $query = mysqli_query($mysqli, $sql); $row = mysqli_fetch_assoc($query); $columnList = implode(', ', array_keys($row)); $sql = "SELECT * FROM list "; $query = mysqli_query($mysqli, $sql); while($row = mysqli_fetch_assoc($query)){ $invoice_id = $row['invoice_id']; $tables = ['sd_order_more'=> 'order_id', 'sd_payment_rcvd' => 'invoiceID', 'sd_order_list' => 'orderID',]; foreach($tables as $key => $value){ $tableName = $key; $columnName = $value; $sql2 = "SELECT * FROM $tableName where $columnName = '$invoice_id'"; $query2 = mysqli_query($mysqli, $sql2); $array = []; while($row3 = mysqli_fetch_assoc($query2)){ foreach($row3 as $key => $value){ if($value == ''){ $array[$key] = 'null'; }else{ $array[$key] = "'" .$value. "'"; } } $valueList = implode(', ', $array); $sql3 = "INSERT INTO $tableName VALUES ($valueList)"; $query3 = mysqli_query($mysqli_online, $sql3); $status = (($query3) ? 'Success' : 'Fail') . "<br>"; echo "Invoice id: " .$invoice_id. " Target table: " .$tableName. " status: " .$status. "<br>"; } } } ?> <!-- sd_order_more x 1 sd_payment_rcvd x 1 sd_order_list x more --> |