Я пытаюсь взять строку из текстового поля VB и отправить ее в свой API, который затем выполняет запрос SQL на обновление данных в таблице «Сотрудники» моей Oracle БД:
Код VB:
Private Sub EditButton_Click(sender As Object, e As EventArgs) Handles editButton.Click
Try
Dim myReq As HttpWebRequest
Dim myResp As HttpWebResponse
Dim myData As String = "{""surname"":" + Chr(34) + sNameBox.Text + Chr(34) + "}"
myReq = HttpWebRequest.Create("http://localhost/projects/DatabaseAPI/editEmployee.php?EMPLOYEE_ID =" + employeeSearchBox.Text + myData)
myReq.Method = "PUT"
myReq.ContentType = "application/json"
Dim encoding As New UTF8Encoding
Dim byteData As Byte() = encoding.GetBytes(myData)
Dim postReqStream As Stream = myReq.GetRequestStream()
postReqStream.Write(byteData, 0, byteData.Length)
postReqStream.Close()
myResp = DirectCast(myReq.GetResponse(), HttpWebResponse)
Dim postReqReader As New StreamReader(myResp.GetResponseStream())
Dim thePage As String = postReqReader.ReadToEnd
MsgBox(thePage)
Catch ex As Exception
MsgBox(ex.Message)
End Try
For Each textBox In Me.Controls
If TypeOf textBox Is TextBox Then
textBox.Text = Nothing
End If
Next
End Sub
PHP Код:
<?php
if (function_exists("oci_connect")){
//echo "oci_connect found\n";
} else {
//echo "oci_connect not found\n";
exit;
}
$tns = "LOCALHOST/ROGERSPDB";
$username = "TESTMANAGE";
$password = "Password";
try{
$conn = oci_connect($username, $password, $tns);
if(!$conn){
$e = oci_error();
throw new Exception($e['message']);
}
//echo "Connection ok\n";
} catch (Exception $e){
print_r($e);
}
if($_SERVER['REQUEST_METHOD'] == 'PUT'){
$json = file_get_contents("php://input");
$data = json_decode($json, TRUE);
$sql = "UPDATE SYS.EMPLOYEES SET SURNAME = :SURNAME WHERE EMPLOYEE_ID = :EMPLOYEE_ID";
$stmt = oci_parse($conn, $sql);
oci_bind_by_name($stmt, ":SURNAME", $data['surame']);
oci_bind_by_name($stmt, ":EMPLOYEE_ID", $_GET['employee_id']);
oci_execute($stmt);
oci_close($conn);
}
?>
У меня такое чувство, что это как-то связано с как я использую URL-адрес API в VB, так как я больше не получаю Oracle ошибок.