PHP ADODB Insert Records with place holder
From w3cyberlearnings
Contents |
PHP ADODB Insert Record
Use Execute method to insert multiple records to the table.
Syntax ADODB INSERT Record
$sql = "INSERT INTO user_infor(id,first_name,last_name, email) values(?,?,?,?) "; $record1 = array(1, 'Paul', 'Mark', '[email protected]'); $conn1->Execute($sql, $record1);
Example 1
<?php include 'adodb5/adodb.inc.php'; $host = 'localhost'; $user = 'user2000'; $pass = 'password2000'; $dbname = 'w3cyberlearning'; $conn1 = &ADONewConnection('mysql'); $conn1->PConnect($host, $user, $pass, $dbname); $sql = "INSERT INTO user_infor(id,first_name,last_name, email) values(?,?,?,?) "; $my_data = array( array(1, 'Paul', 'Mark', '[email protected]'), array(2, 'Jam', 'Gill', '[email protected]'), array(3, 'Mix', 'Alex', '[email protected]'), array(4, 'King', 'Mix', '[email protected]') ); for ($i = 0; $i < count($my_data); $i++) { $d = $conn1->Execute($sql, $my_data[$i]); if (!$d) { print 'error' . $conn1->ErrorMsg() . '<br>'; } echo 'Success!'; echo "<br/>"; } ?>
Related Links
- PHP ADODB Tutorial
- PHP ADODB Connect
- PHP ADODB Create Table
- PHP ADODB Insert Records with Place Holder