<?php required_once('config.php');
required_once('class/class.Database.php');
$dbObj = new Database();
//to get list
$query = '
SELECT
*
FROM
test1
WHERE
test1.abc = :ABC
AND
test1.xyz = :XYZ
';
$stmt = $dbObj->prepare($query);
$dbObj->bind($stmt, ':ABC', $abc);
$dbObj->bind($stmt, ':XYZ', $xyz);
$dbObj->execute($stmt);
if (!empty($dbObj->displayError())) {
throw new Exception($dbObj->displayError());
}
$list = $dbObj->fetchSqlData($stmt);
// To Insert
$query = '
INSERT INTO
test1
(
abc,
efg,
xyz
)
VALUES
(
:ABC,
:EFG,
:XYZ
)
';
$stmt = $dbObj->prepare($query);
$dbObj->bind($stmt, ':ABC', $abc);
$dbObj->bind($stmt, ':EFG', $efg);
$dbObj->bind($stmt, ':XYZ', $xyz);
$dbObj->execute($stmt);
if (!empty($dbObj->displayError())) {
throw new Exception($dbObj->displayError());
}
// To Insert multiple rows
$query = '
INSERT INTO
test1
(
abc,
efg,
xyz
)
VALUES
';
$insertSql = [];
for ($index = 1; $index < 1000; $index++) {
$nameIndex = 'EFG_'.$index; //dummy data
$rank = $index * 10; //dummy data
$insertSql[] = sprintf(
"( %d, %d, %d)",
$index,
$nameIndex,
$rank
);
}
$dbObj->saveMultipleInsertQuery($query, $insertSql);
|