Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/2-insert_1row.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 2013-09-04 02:05
Size: 960 bytes
 

Contents

Class file image Download
<?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;