mysql基本增刪改查

get_hoter發表於2020-12-15

基本資訊

$mysql_host = 'localhost';  //域名
$mysql_user = 'exp_root';	//賬號
$mysql_pwd = '123456';		//密碼
$mysql_dbname = 'exp';		//庫名

連線

$con= mysqli_connect($mysql_host, $mysql_user, $mysql_pwd, $mysql_dbname); 
// 檢查連線
if (!$con)
{
    die("連線錯誤: " . mysqli_connect_error());
}else {
	echo 'success';
}

$sql = "select * from class";
$result = $con->query($sql);
$row = $result ->fetch_assoc();
//var_dump($row);

$sql = "insert into class (name, sex, tall) values('李四', 'm', 163)";
$con -> query($sql); // 若插入成功,則返回true

$sql = "update class set tall = 177 where name='李四'";
$con -> query($sql); // 若修改成功,則返回true

$sql = "delete from class where name='李四'";
$con -> query($sql); // 若刪除成功,則返回true

相關文章