v5:userguide:portable_sql
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
v5:userguide:portable_sql [2016/02/27 18:42] – mnewnham | v5:userguide:portable_sql [2020/12/30 21:32] (current) – [Prepare/Execute] fix obvious variable case typos peterdd | ||
---|---|---|---|
Line 29: | Line 29: | ||
<code php> | <code php> | ||
- | $connection-> | + | $connection-> |
</ | </ | ||
Line 49: | Line 49: | ||
<code php> | <code php> | ||
- | $rs = $db->Execute(" | + | $rs = $db->execute(" |
- | $numrows = $rs->PO_RecordCount(' | + | $numrows = $rs->po_recordCount(' |
</ | </ | ||
Line 60: | Line 60: | ||
<code php> | <code php> | ||
- | $connection-> | + | $connection-> |
- | $connection-> | + | $connection-> |
# some operation | # some operation | ||
- | if ($ok) $connection-> | + | if ($ok) $connection-> |
- | else $connection-> | + | else $connection-> |
</ | </ | ||
Line 98: | Line 98: | ||
===== Inserting Records ===== | ===== Inserting Records ===== | ||
- | When you create records, you need to generate unique id's for each record. There are two common techniques: | + | When you create records, you need to generate unique id's for each record. There are two common techniques: |
+ | * Auto-increment | ||
+ | * Sequences | ||
- | Auto-incrementing | + | Auto-increment |
+ | |||
+ | Different tables can have different sequences. | ||
<code php> | <code php> | ||
- | $id = $connection-> | + | $id = $connection-> |
- | $connection-> | + | $connection-> |
- | values ($id, $firstname, $lastname)" | + | values ($id, $firstname, $lastname)" |
</ | </ | ||
- | For databases that do not support | + | For databases that do not provide native |
===== Binding ===== | ===== Binding ===== | ||
Line 116: | Line 120: | ||
===== Prepare/ | ===== Prepare/ | ||
<code php> | <code php> | ||
- | $stmt = $db->Prepare(' | + | $stmt = $db->prepare(' |
- | $rs = $db->Execute($stmt, array($id,' | + | $rs = $db->execute($stmt, array($id,' |
/* | /* | ||
Oracle uses named bind placeholders, | Oracle uses named bind placeholders, | ||
*/ | */ | ||
- | $sql = ' | + | $sql = ' |
# generates ' | # generates ' | ||
# or ' | # or ' | ||
- | $stmt = $DB->Prepare($sql); | + | $stmt = $db->prepare($sql); |
- | $stmt = $DB->Execute($stmt, | + | $stmt = $db->execute($stmt, array(' |
</ | </ | ||
Line 170: | Line 174: | ||
AGE N(16) DEFAULT 0 | AGE N(16) DEFAULT 0 | ||
"; | "; | ||
- | $sql1 = $datadict-> | + | $sql1 = $datadict-> |
- | $sql2 = $datadict-> | + | $sql2 = $datadict-> |
</ | </ | ||
Line 182: | Line 186: | ||
<code php> | <code php> | ||
- | $date1 = $connection-> | + | $date1 = $connection-> |
- | $date2 = $connection-> | + | $date2 = $connection-> |
</ | </ | ||
We also provide functions to convert database dates to Unix timestamps: | We also provide functions to convert database dates to Unix timestamps: | ||
<code php> | <code php> | ||
- | $unixts = $recordset-> | + | $unixts = $recordset-> |
</ | </ | ||
Line 194: | Line 198: | ||
<code php> | <code php> | ||
- | $sql = ' | + | $sql = ' |
</ | </ | ||
Line 201: | Line 205: | ||
<code php> | <code php> | ||
# for oracle | # for oracle | ||
- | $conn->Execute(' | + | $conn->execute(' |
- | $conn->UpdateBlob(' | + | $conn->updateBlob(' |
# non-oracle databases | # non-oracle databases | ||
- | $conn->Execute(' | + | $conn->execute(' |
- | $conn->UpdateBlob(' | + | $conn->updateBlob(' |
</ | </ | ||
Line 233: | Line 237: | ||
} | } | ||
# @RETVAL = SP_RUNSOMETHING @myid, | # @RETVAL = SP_RUNSOMETHING @myid, | ||
- | $stmt = $db->PrepareSP($sql); | + | $stmt = $db->prepareSP($sql); |
$db-> | $db-> | ||
- | $db->Parameter($stmt, | + | $db->parameter($stmt, |
# true indicates output parameter | # true indicates output parameter | ||
- | $db->Parameter($stmt, | + | $db->parameter($stmt, |
- | $db->Execute($stmt); | + | $db->execute($stmt); |
</ | </ | ||
Line 249: | Line 253: | ||
<code php> | <code php> | ||
$sqlGetPassword = ' | $sqlGetPassword = ' | ||
- | $sqlSearchKeyword = quot;SELECT * FROM articles WHERE match (title, | + | $sqlSearchKeyword = "SELECT * FROM articles WHERE match (title, |
</ | </ | ||
Line 259: | Line 263: | ||
include_once(" | include_once(" | ||
- | $db = NewADOConnection($database); | + | $db = newADOConnection($database); |
- | $db->PConnect(...) or die(' | + | $db->pConnect(...) or die(' |
# search for a keyword $word | # search for a keyword $word | ||
- | $rs = $db->Execute(sprintf($sqlSearchKeyWord, | + | $rs = $db->execute(sprintf($sqlSearchKeyWord, |
</ | </ |
v5/userguide/portable_sql.1456594920.txt.gz · Last modified: 2017/04/21 11:39 (external edit)