mysqli連線資料庫

SpringCloud1發表於2018-05-18
<?php
header("charset=UTF-8");

$link = mysqli_connect(
'localhost', /* The host to connect to 連線MySQL地址 */
'root', /* The user to connect as 連線MySQL使用者名稱 */
'xuex', /* The password to use 連線MySQL密碼 */
'ssm'); /* The default database to query 連線資料庫名稱*/

if(!$link){
printf("Can't connect to Mysql ",mysqli_connect_error());
}
if ($result = mysqli_query($link, 'SELECT emp_id, gender FROM tbl_emp ORDER BY emp_name DESC LIMIT 5')) {
//print("Very large cities are: ");
/* Fetch the results of the query 返回查詢的結果 */
while( $row = mysqli_fetch_assoc($result) ){
printf("%s (%s) ", $row['emp_id'], $row['gender']);
}
/* Destroy the result set and free the memory used for it 結束查詢釋放記憶體 */
mysqli_free_result($result);
}
/* Close the connection 關閉連線*/
mysqli_close($link);

?>

相關文章