<?php
// includes the file that contains data for connecting to mysql database, and PDO_MySQLi class
include('../conn_mysql.php');
// creates object with connection to MySQL
$conn = new PDO_MySQLi($mysql);
// INSERT one row, with corresponding placeholder names in the SQL statement, and array with values for associated names
$sql = "INSERT INTO `testclass` (`url`, `title`, `dt`) VALUES (:url, :title, :dt)";
$vals = array('url'=>'http://coursesweb.net/', 'title'=>'Web Development Courses', 'dt'=>time());
// executes the SQL query, passing the SQL and the array with values
$resql = $conn->sqlExecute($sql, $vals);
$last_id = $conn->last_insertid; // gets last inserted Auto-Increment ID
// check if the SQL query succesfully performed, and displays the number of affected (inserted) rows, and last ID
if($resql) echo 'Inserted succesfully '. $conn->affected_rows .' row. Last inserted ID: '. $last_id;
else echo $conn->error;
|