2012-04-14 2 views
3

다음 코드를 사용하여 테이블에서 항목을 제거하려면 원하는 값이 테이블에서 삭제되었는지 확인하는 것이 좋습니다. 한 값이 삭제되면 스크립트가 인쇄됩니다 성공을 다른 false.This 내가 now.Please 도움까지 달성 한 것입니다PHP 스크립트에서 Mysqli DELETE QUERY가 작동하지 않음

당신이 반환해야 무엇을 삭제할 것을
<?PHP 
    $mysqli = new mysqli("SQLHOST.COM","CLIENT","PASSWORD", "DNAME", 1234); 

    if ($mysqli->connect_errno) { 
     printf("Connect failed: %s\n", $mysqli->connect_error); 
     exit(); 
    } 
    else 
    { 

    printf("cONN Sucees"); 


    if ($result = $mysqli->query("DELETE FROM ktable WHERE code='value'")) { 
     printf("Select returned %d rows.\n", $result->num_rows); 


    printf($result->num_rows); 
     $result->close(); 
    } 

    } 
    ?> 

답변

9

if ($result = $mysqli->query("DELETE FROM ktable WHERE code='value'")) { 
    printf("Select returned %d rows.\n", $result->num_rows); 


    printf($result->num_rows); 
    $result->close(); 
} 
를 교체 할 필요가 무엇 affected_rows http://www.php.net/manual/en/mysqli.affected-rows.php

입니다 0

작업 코드

$value = ""; // Set To any Value 
$mysqli = new mysqli ("SQLHOST.COM", "CLIENT", "PASSWORD", "DNAME", 1234); 
if ($mysqli->connect_errno) { 
    printf ("Connect failed: %s\n", $mysqli->connect_error); 
    exit(); 
} else { 
    printf ("cONN Sucees"); 
    if ($mysqli->query (sprintf ("DELETE FROM ktable WHERE code='%s'", mysqli_real_escape_string ($mysqli, $value)))) { 
     printf ("Affected Rows %d rows.\n", $mysqli->affected_rows); 
    } 
} 

당신은 어떻게 execption 사용에 대한 작업 출력

+0

thanks.it 작품. – techno

-1

이 있어야합니다. 나는 또한 코드를 조금 바꿨다.

<?php 
$mysqli = new mysqli("SQLHOST.COM", "CLIENT", "PASSWORD", "DNAME", 1234); 
$connection = mysqli_connect('SQLHOST', 'CLIENT', 'PASSWORD') or die(mysqli_error()); 
try { 
    $select_db = mysqli_select_db('DBNAME', $connection); 
    if (!$select_db) { 
     throw new Exception("Could not connect!"); 
    } 
} 
catch (exception $e) { 
    echo "Error (File: " . getFile() . ", line " . $e->getLine() . "): " . $e-> 
     getMessage(); 
} 
$query = mysqli_query('DELETE FROM ktable WHERE code="' . $value . ';"'); 
    if ($query) { 

     printf("Select returned %d rows.\n", $result->num_rows); 
     printf($result->num_rows); 
     mysqli_close(); 
    } 
?>