PHP ### Database/MySQL ============== SELECT ****** .. code-block:: php $conn = new mysqli("", "", "", ""); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM WHERE ;"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { // Do your Stuff (acces values with $row[""]) } } $conn->close(); INSERT ****** .. code-block:: php $conn = new mysqli("", "", "", ""); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Simple Query $query = "INSERT INTO
(, ) VALUES ('', '')"; // Prevent SQL-Injection $query = sprintf("SELECT CountryCode FROM City WHERE name='%s'", $mysqli->real_escape_string($city)); if ($conn->query($query) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $query . "
" . $conn->error; } $conn->close(); REMOVE ****** .. code-block:: php $conn = new mysqli("", "", "", ""); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "DELETE FROM
WHERE ;"; if ($conn->query($sql) === TRUE) { $ret_obj->message = "Entrys deleted"; } else { $ret_obj->message = "Error deleting record: " . $conn->error; } $conn->close(); Error Reporting =============== .. code-block:: php Create Objects (for JSON-API) ============================= .. code-block:: php $ret_array = []; //... while($row = $result->fetch_assoc()) { $tempObj = new stdClass(); $tempObj->value_1 = "Hello World"; $tempObj->value_2 = "TEST_1234"; $tempObj->count = $row["COUNT(*)"]; array_push($ret_array, $tempObj); } //... return $ret_array; XML Interacting =============== .. code-block:: php $xml_content = simplexml_load_string($xml_string) print($xml_content->getName()."
"); foreach ($xml_content->children() as $child){ print("::". $child->getName() ."
"); foreach ($child->children() as $grand_child){ print(":::::". $grand_child->getName() ."
"); } } Get Content of First Child ************************** .. code-block:: php print(simplexml_load_string($resp)->children()[0][0]); cURL (Web-Requests) =================== .. code-block:: php $url = ; $curl = curl_init($url); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $resp = curl_exec($curl); curl_close($curl); API-Example =========== .. code-block:: php "; $username = ""; $password = ""; $dbname = ""; $conn = new mysqli($servername, $username, $password, $dbname); if (isset($_GET["function"])) { $function = $_GET["function"]; } else { $function = ""; } if (isset($_GET[""])) { $param_2 = $_GET[""]; } else { $param_2 = ""; } if ($function == "") { $sql = "SELECT * FROM
"; $result = $conn->query($sql); $events_array; $events_array[''] = []; if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { $event = new stdClass(); $event->value_1 = $row[""]; $event->value_2 = $row[""]; array_push($events_array[''], $event); } } $messageObject->message = $events_array; $messageObject->code = 200; } else { $messageObject->message = "Please specifi which function you want to call."; $messageObject->code = 200; } } catch (exception $e) { $messageObject->message = "Something went wrong!"; $messageObject->code = 500; $messageObject->error = "Message: ".$e; } finally { $conn->close(); header('Content-Type: application/json'); echo json_encode($messageObject); } ?> CSV export for Excel ==================== .. code-block:: php array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); $url = "get_your_content"; $content = file_get_contents($url, false, stream_context_create($arrContextOptions)); $content = json_decode($content, true); for ($x = 0; $x < sizeof($content['message']['...']); $x++) { // do your stuff here } $output = fopen("php://output", "w"); header('Content-Type: application/csv'); header('Content-Disposition: attachment; filename="yourFile.csv"'); fputs($output, $bom = (chr(0xEF) . chr(0xBB) . chr(0xBF))); fputs($output, $text); ?>