PHP Classes

File: examples/2-insert_1row.php

Recommend this page to a friend!
  Classes of MarPlo   PDO_MySQLi class   examples/2-insert_1row.php   Download  
File: examples/2-insert_1row.php
Role: Example script
Content type: text/plain
Description: Example 2
Class: PDO_MySQLi class
Access MySQL using PDO or MySQLi extensions
Author: By
Last change:
Date: 10 years ago
Size: 960 bytes


Class file image Download
// includes the file that contains data for connecting to mysql database, and PDO_MySQLi class

// 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'=>'', '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