2016-11-25 432 views
-2
function inseartinto() 
{ 
    $DEL_LOG_REP = $connection->prepare("DELETE FROM test WHERE itemname='111'")$DEL_LOG_REP->execute()$DEL_LOG_REP->close()return $DEL_LOG_REP 
} 
+3

你有問題。這不是一個有效的PHP,並且$ connection不在函數範圍內。 –

回答

0
This is short tutorails on connection in insert query into php... 
<?php 
    $servername = "localhost"; 
    $username = "username"; 
    $password = "password"; 
    $dbname = "myDB"; 

    // Create connection 
    $conn = new mysqli($servername, $username, $password, $dbname); 
    // Check connection 
    if ($conn->connect_error) { 
     die("Connection failed: " . $conn->connect_error); 
    } 

    $sql = "INSERT INTO MyGuests (firstname, lastname, email) 
    VALUES ('John', 'Doe', '[email protected]')"; 

    if ($conn->query($sql) === TRUE) { 
     echo "New record created successfully"; 
    } else { 
     echo "Error: " . $sql . "<br>" . $conn->error; 
    } 

    $conn->close(); 
    ?> 

更多更好understand..go到http://www.w3schools.com/php/default.asp

+0

我已經完成了連接部分,我需要知道如何在類和函數中寫入查詢.... – Ashan

0

你想編寫人什麼代碼.. 這不是真的不是一個有效的代碼插入,但也爲連接.. 亞去@Sasa.D提到W3School.com ...它爲您提供從基本知識到專業知識..