สรุปคำสั่ง insert update delete select ของ adodb SQL


หน้าแรก PHP MySQL เกร็ดความรู้ สรุปคำสั่ง insert update delete select ของ adodb SQL

include("adodb/adodb.inc.php");
$DBConf = "mysql://username:password@localhost/table";
$conn = ADONewConnection($DBConf);
$debug = 1;

//START select
$sql = "SELECT * FROM ado ORDER BY id ASC";
$rs = $conn->Execute($sql);
if (!$rs)
    print $conn->ErrorMsg();
else
    while (!$rs->EOF) {
        print $rs->fields[1];
  $rs->MoveNext();
  echo"
";
    }
$rs->close();
$conn->close();
//END select


//START insert
echo "$DBConf";
$r=rand(1,99999);
//$r="asdฟหกฟหก";
$sql = "INSERT INTO ado (topic) values ('$r')";
$rs = $conn->Execute($sql);
if(!$rs){ echo"failed.";} else { echo"OK";}
//END insert

// START insert type 2
$sql = "SELECT * FROM ado WHERE id = -1";
$rs = $conn->Execute($sql);
$record = array();
$record['topic'] = 'value1';
$insertSQL = $conn->GetInsertSQL($rs, $record);
$conn->Execute($insertSQL);
if(!$insertSQL){ echo"failed.";} else { echo"OK";}
// END insert type 2

//START update
$sql = 'SELECT * FROM table WHERE id = 4';
$rs = $conn->Execute($sql);
$record = array();
$record['field'] = 'val874';
$updateSQL = $conn->GetUpdateSQL($rs, $record);
$conn->Execute($updateSQL);
if(!$updateSQL){ echo"failed.";} else { echo"OK";}
//END update

//START delete
$conn->Execute("delete from table where id=4"); 
if(!$conn){ echo"failed.";} else { echo"OK";}
//END delete

refer: http://phplens.com/lens/adodb/docs-adodb.htm



ขึ้นไปด้านบน