ก่อนอื่นต้องทำการเชื่อมต่อฐานข้อมูล ถ้ายังทำไม่เป็นคลิกอ่านก่อนเลย PHP connect SQL
ตัวอย่างการใช้งานจริง Code PHP Mysql Query
ข้อมูลจากฐานข้อมูลมาแสดงในหน้าเว็บไซต์
$sql = "SELECT
wp_options.option_id,
wp_options.option_name
FROM `wp_options`
ORDER BY wp_options.option_id ASC
LIMIT 10";
$result = mysqli_query($connect, $sql);
foreach ($result as $key => $detail){
echo $key." :: ";
print_r($detail);
echo "<hr>";
}
wp_options.option_id,
wp_options.option_name
FROM `wp_options`
ORDER BY wp_options.option_id ASC
LIMIT 10";
$result = mysqli_query($connect, $sql);
foreach ($result as $key => $detail){
echo $key." :: ";
print_r($detail);
echo "<hr>";
}
ผลลัพธ์
0 :: Array ( [option_id] => 1 [option_name] => siteurl )
1 :: Array ( [option_id] => 2 [option_name] => home )
2 :: Array ( [option_id] => 3 [option_name] => blogname )
3 :: Array ( [option_id] => 4 [option_name] => blogdescription )
4 :: Array ( [option_id] => 5 [option_name] => users_can_register )
5 :: Array ( [option_id] => 6 [option_name] => admin_email )
6 :: Array ( [option_id] => 7 [option_name] => start_of_week )
7 :: Array ( [option_id] => 8 [option_name] => use_balanceTags )
8 :: Array ( [option_id] => 9 [option_name] => use_smilies )
9 :: Array ( [option_id] => 10 [option_name] => require_name_email )