June 2017
Intermediate to advanced
536 pages
9h 49m
English
Now that we have learned how to prepare a query and bind data to it, inserting new records becomes pretty easy:
<?phptry { // Report on all types of errors mysqli_report(MYSQLI_REPORT_ALL); // Open a new connection to the MySQL server $mysqli = new mysqli('127.0.0.1', 'root', 'mL08e!Tq', 'sakila'); // Prepare some teat address data $address = 'The street'; $district = 'The district'; $cityId = 135; // Matches the Dallas city in Sakila DB $postalCode = '31000'; $phone = '123456789'; // Prepare an SQL statement for execution $statement = $mysqli->prepare('INSERT INTO address ( address, district, city_id, postal_code, phone ) VALUES ( ?, ?, ?, ?, ? ); '); // Bind variables to a prepared statement as parameters $statement->bind_param( ...
Read now
Unlock full access