connect_error) { return 0; } $sql = 'UPDATE sequence SET id=LAST_INSERT_ID(id+1);'; $result = $conn->query($sql); if ( $result ){ $sql ='SELECT * FROM `sequence` '; // SELECT LAST_INSERT_ID()'; $result = $conn->query($sql); if ( $result ){ while ( $row = $result->fetch_array() ) { $sequence = intval($row[0]) ; } // while } // if } else { // die('SQL-Anweisung gescheitert'); $sequence = 0; } return $sequence; } function getConnection() { $servername = 'localhost'; $username = 'root'; $passwd = ''; $database = 'amacon'; $conn = new mysqli($servername, $username,$passwd,$database); if ($conn->connect_error) { //die('Connection failed: ' . $conn->connect_error); } return $conn; } // getConnection function loadCustomersFromDB() { $result = new Result(); $conn = getConnection(); if ($conn->connect_error) { $result->isError=true; $result->errortext='Es konnte keine Verbindung zur Datenbank hergestellt werden'; return $result; } $sql = 'SELECT pindex, cno, lastname, firstname, street, birthday FROM customer'; $resultSQL = $conn->query($sql); if ($resultSQL) { while($row = $resultSQL->fetch_array()) { $customer = new Customer(); $customer->pindex = intval($row['pindex']); // assoziatives Array $customer->cno = intval($row['cno']); // assoziatives Array $customer->lastname = $row['lastname']; // assoziatives Array $customer->firstname = $row['firstname']; // assoziatives Array $customer->street = $row['street']; // assoziatives Array $customer->birthday = $row['birthday']; // assoziatives Array $result->arr[] = $customer; } } // if return $result; } function loadCustomerFromDB($pindex) { $result = new Result(); $conn = getConnection(); if ($conn->connect_error) { $result->isError=true; $result->errortext='Es konnte keine Verbindung zur Datenbank hergestellt werden'; return $result; } $sql = 'SELECT pindex, cno, lastname, firstname, street, birthday FROM customer ' . ' WHERE pindex=' . $pindex; $resultSQL = $conn->query($sql); if ($resultSQL) { while($row = $resultSQL->fetch_array()) { $customer = new Customer(); $customer->pindex = intval($row['pindex']); // assoziatives Array $customer->cno = intval($row['cno']); // assoziatives Array $customer->lastname = $row['lastname']; // assoziatives Array $customer->firstname = $row['firstname']; // assoziatives Array $customer->street = $row['street']; // assoziatives Array $customer->birthday = $row['birthday']; // assoziatives Array $result->arr[] = $customer; break; } } // if return $result; } // loadCustomerFromDB function updateCustomerDB($customer) { $result = new Result(); $sql = 'UPDATE customer ' . 'SET ' . ' `CNO`=' . $customer->cno . ', ' . ' `LASTNAME`=' . quoted($customer->lastname) . ', ' . ' `FIRSTNAME`=' . quoted($customer->firstname) . ', ' . ' `STREET`=' . quoted($customer->street) . ', ' . ' `BIRTHDAY`=' . quoted($customer->birthday) . ' WHERE `PINDEX`=' . $customer->pindex; $conn = getConnection(); if ($conn->connect_error) { $result->isError=true; $result->errortext = "Keine Verbindung zur Datenbank" . '
'; // return false; } $resultsql = $conn->query($sql); if ($resultsql) { // hier war alles in Ordnung! } else { $result->isError=true; $result->errortext = $sql . '
' . $conn->error . '
'; } return $result; } // updateCustomerDB function deleteCustomerDB($pindex) { $result = new Result(); $sql = 'DELETE FROM customer ' . ' WHERE `PINDEX`=' . $pindex; $conn = getConnection(); if ($conn->connect_error) { $result->isError=true; $result->errortext = "Keine Verbindung zur Datenbank" . '
'; // return false; } $resultsql = $conn->query($sql); if ($resultsql) { // hier war alles in Ordnung! } else { $result->isError=true; $result->errortext = $sql . '
' . $conn->error . '
'; } return $result; } // deleteCustomerDB function newCustomerDB($customer) { $result = new Result(); $conn = getConnection(); if ($conn->connect_error) { $result->isError=true; $result->errortext = "Keine Verbindung zur Datenbank" . '
'; } $sql = 'INSERT INTO customer(PINDEX, CNO, LASTNAME, FIRSTNAME, STREET, BIRTHDAY)' . ' VALUES( ' . ' ' . $customer->pindex . ', ' . ' ' . $customer->cno . ', ' . ' ' . quoted($customer->lastname) . ', ' . ' ' . quoted($customer->firstname) . ', ' . ' ' . quoted($customer->street) . ', ' . ' ' . quoted($customer->birthday) . ' )'; if ($conn->query($sql)) { // alles okay } else { $result->isError=true; $result->errortext = $sql . '
' . $conn->error . '
'; } return $result; } // insertCustomerDB ?>