php對Mysql基本程式設計

2021-09-19 01:25:46 字數 657 閱讀 1473

1、建立php工程

2、分別定義mysql資料庫的ip位址、使用者名稱、使用者密碼、資料庫名

$servername = 「localhost」;

$username = "username ";

$password = "password ";

$dbname = 「mysql」;

3、用方法mysqli_connect例項化mysqli

4、用mysqli的query方法查詢資料集

5、用資料集的fetch_assoc()方法遍歷資料集

<?php

$servername = "localhost";

$username = "username ";

$password = "password ";

$dbname = "mysql";

try else

} catch (exception $e)

$sql = "select host, user from user";

$result = $conn->query($sql);

if ($result->num_rows > 0)

} else

$conn->close();

?>

PHP實驗二 PHP基本程式設計

1.求 乙個一維 陣列的最大值 求乙個一維陣列的最大值 num array 1,5,3,515,45,32,18 max num 0 for i 1 i echo 陣列中最大的數為 max 2.求乙個一維 陣列的元素之和 求乙個一維陣列的元素之和 arr array 4,6,2,22,11 sum ...

php對mysql的了解 對MySQL的初步了解

首先安裝mysql 一.單詞部分 networking網路 option選擇 port埠 firewall防火牆 engine引擎 standard標準 character字元 collation校對 stirage儲存 二.預習部分 1.請寫出建立和刪除資料庫的sql語句 create datab...

php 實驗2 php基本程式設計

實驗目的 掌握php語法基本元素,掌握資料型別 變數和常量 運算子 表示式的使用 掌握php流程控制 實驗內容及要求 求乙個一維陣列的最大值。header content type text html charset utf 8 arr1 1,5,9,8,2,5 max arr1 0 for i 0...