Example 3
In this example we will make an automatic insert with MkInsert and then get the complete table contents.
Afterwards we will delete the last set from the table and make another select to control the success.
We will again simulate the form requests by creating the array $FAKE_REQUEST. Program File # 1: <?php 
# 2:
require_once("../fastsql.inc");
# 3:
define("G_HOST""localhost");
# 4:
define("G_DBUSER""MyUsername");
# 5:
define("G_DBPWD""MyPassword");
# 6:
define("G_NORMDB""MyDB");
# 7:
# 8:
$FAKE_REQUEST = array("Name"=>"Annie",
# 9:               
"Phone"=>"8654454576"
#10:               
);
#11:               
#12:               
#13:
$FAKE_REQUEST['CREATED'] = date("YmdHis");
#14:               
#15:
$conn = new FastSQL;
#16:
$insert_id $conn->MkInsert("ADDRESSES"G_NORMDB$FAKE_REQUEST, array("ID","MODIFIED"));
#17:
#18:
$select "select * from ADDRESSES order by Name";
#19:
$res $conn->query($selectG_NORMDB);
#20: print 
"<pre>";
#21:
print_r($res);
#22: print 
"</pre>";
#23:
#24:
?>
The result will look like this # 0: <?
# 1:
Array
# 2: (
# 3:     [
0] => Array
# 4:         (
# 5:             [
ID] => 5
# 6:             
[Name] => Annie
# 7:             
[Phone] => 8654454576
# 8:             
[MODIFIED] => 20050814194129
# 9:             
[CREATED] => 20050814194129
#10:         
)
#12:     [
1] => Array
#13:         (
#14:             [
ID] => 4
#15:             
[Name] => Harry
#16:             
[Phone] => 8743 5323
#17:             
[MODIFIED] => 20050814191831
#18:             
[CREATED] => 20050814185937
#19:         
)
#21:     [
2] => Array
#22:         (
#23:             [
ID] => 2
#24:             
[Name] => Jill
#25:             
[Phone] => 4785521
#26:             
[MODIFIED] => 20050814180607
#27:             
[CREATED] => 00000000000000
#28:         
)
#30:     [
3] => Array
#31:         (
#32:             [
ID] => 1
#33:             
[Name] => John
#34:             
[Phone] => 28877112
#35:             
[MODIFIED] => 20050814180607
#36:             
[CREATED] => 00000000000000
#37:         
)
#39:     [
4] => Array
#40:         (
#41:             [
ID] => 3
#42:             
[Name] => My dog
#43:             
[Phone] => 04487 445512
#44:             
[MODIFIED] => 20050814180607
#45:             
[CREATED] => 00000000000000
#46:         
)
#48: )
The MkInsert function takes our Fake form data array as is and uses it for an SQL statement.
Now, that makes developing life a lot easier, right? However, there is also the field "CREATED" that must be filled and which is not provided in the $FAKE_REQUEST array. So we have to add it manually.

My Sites