2013-11-26 88 views
0

我從w3schools得到了這個php腳本,我想知道是否可能只刪除姓並留下彼得的名字?從數據庫中只刪除某些東西

<?php 
$con=mysqli_connect("example.com","peter","abc123","my_db"); 
// Check connection 
if (mysqli_connect_errno()) 
{ 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

mysqli_query($con,"DELETE FROM Persons WHERE LastName='Griffin'"); 

mysqli_close($con); 
?> 

來源: http://www.w3schools.com/php/php_mysql_delete.asp

+1

你需要做'UPDATE'和'SET'(替換)爲了做到這一點,「格里芬」沒有任何東西。 –

回答

1

是的,只是做

UPDATE Persons 
    set LastName = '' 
WHERE 
    id = ? 

或備選地,設置姓氏= NULL

+2

「人員」而不是「人員」;-)查看OP的代碼。列和表格區分大小寫。 –

+0

woops,thanks fred – echochamber

+0

沒問題;-) –