۲۸-مرداد-۱۳۹۲, ۲۰:۲۸:۳۷
PDO DB Class, Execute common MySQL
مثال:
مثال:
کد php:
<?php
include("db.pdo.php");
/*Note **Table name and filed name mentioned here as per instalation Sql Script
You can change it your own way */
$table="crm_typelead";
echo " Here is For PDO MYSQL <br>";
////////////////////////////////////////////////// seelecting first instance
echo "selecting before insertion and Updation<br>";
$sql = "SELECT * FROM ".$table."";//query
$row =$db->select($sql);//selecting
echo '<table width="40%" border="1"><tr><td>Id</td><td>Name</td></tr>';
for($i=0;$i<count($row);$i++){
echo "<tr>" ;
echo "<td>".$row[$i]['typelead_id']."</td>";
echo "<td>".$row[$i]['typelead_name']."</td>";
echo "</tr>";
}
echo "</table>";
//
///////////////////////
echo "Here Insertion Operation <br>";
$val= $db->sqlsafe('good boy zamin Mohamed P T');//fliter data
$ar = array ('typelead_name' =>$val);// array
$res = $db->insert($table,$ar);//insertion code
if($res!=0){echo 'Inserted <br>Last Inserted Id :'.$res;}else{echo "not inserted<br>";}
///////////////////////////////////////////////////////////
echo "here need to upadate first row as some name <br>";
$val2= $db->sqlsafe('Zamin My baby');// filtering data
$ar2 = array ('typelead_name' =>$val2);//aarry here
$where='typelead_id = 1';///condtion
$res = $db->update($table, $ar2 , $where);
if($res==1){echo 'Updated <br>';}else{echo "not Updated<br>";}
/////////////////////////////////////////////////////////
////////////////////////////////delete one row
//echo 'Here we delete one row (33)<br>';
//$where='typelead_id = 33';///condtion
//$res= $db->delete($table,$where);
//echo $res;
//if($res==TRUE){echo 'Deleted <br>';}else{echo "not Deleted<br>";}
echo "selecting After insertion and Updation<br>";
$sql = "SELECT * FROM ".$table."";//query
$row =$db->select($sql);//selecting
echo '<table width="40%" border="1"><tr><td>Id</td><td>Name</td></tr>';
for($i=0;$i<count($row);$i++){
echo "<tr>" ;
echo "<td>".$row[$i]['typelead_id']."</td>";
echo "<td>".$row[$i]['typelead_name']."</td>";
echo "</tr>";
}
echo "</table>";
$db->close();///connection release here
//
?>