Frustration can be good...and bad!
In my previous post, I was eluding to the frustration of getting onto the system and beginning the reality of connecting and doing something with data already on the system. To my happiness, I found things to be much more enjoyable than it was earlier.
Getting connected was just some trial and error on my part. Permissions, UserID, Passwords (buying the System Admin a beer) -- you know, doing whatever it takes!
This brought me to a quick and easy execution of a SQL statement on the Host:
Looking at the above code... a few notes of things that drove me nuts .. (a short trip, but worth it)
--The basic flow of Data Retrieval is:
Assign Query ( $qry above )
Prepare the Query ( i5_prepare )
Bind the Parameters *if needed* (i5_bind_param)
Execute the Query (i5_execute)
Fetch the data (i5_fetch_assoc)
** Side Note ** from past experience, I like the ASSOC better than ARRAY on the Fetch due to the clean look on using what was retrieved. At that point, you can use the $row['VARNAME'] format so it's easier to debug and or maintain down the road. (But, that's just me)
--Notice the use of Parameters. This allows for building a form, prompting for search criteria and never having to change the QRY statement. They are bound (in order) by the i5_bind_param function. Not a requirement, but does come in handy....
This is just a start, but it does allow me to start moving in quite a few different directions. Mainly ... the one that *hopefully* pushes my company to use this moving forward!
PS: Thanks to those websites that help with syntax and flow... too many to list -- but, I have no problems recognizing those who help others!
Until Next time...
In my previous post, I was eluding to the frustration of getting onto the system and beginning the reality of connecting and doing something with data already on the system. To my happiness, I found things to be much more enjoyable than it was earlier.
Getting connected was just some trial and error on my part. Permissions, UserID, Passwords (buying the System Admin a beer) -- you know, doing whatever it takes!
This brought me to a quick and easy execution of a SQL statement on the Host:
PHP Code:
<?php
$i5_server_ip = "localhost";
$i5_uname = "UserName";
$i5_pass = "Password";
$conn = i5_connect($i5_server_ip, $i5_uname, $i5_pass);
if ($conn === false)
{
print ("FAIL : Failed to connect to server : $i5_server_ip,
with user name : $i5_uname
and password : $i5_pass <br>\n");
$errorTab = i5_error();
var_dump($errorTab);
die();
} else {
echo "We have connection to the System : $i5_server_ip <br><br>\n";
}
$Store = 3301;
$qry = "Select StrNum, StrNam, StPhon from Library/Stores Where STRNUM=?";
$req = i5_prepare( $qry );
If ( !$req ) {
Echo "Prepare Issues!";
die();
}
i5_bind_param( $req, &$Store );
$result = i5_execute( $req );
if( !$result ) {
Echo "Result Issues!";
i5_close( $conn );
die();
}
$row = i5_fetch_assoc( $req );
If ( $row ) {
echo "Store# " .$row['STRNUM']. "<br>";
echo " Name: " .$row['STRNAM']. "<br>";
echo "Phone: " .$row['STPHON']. "<br>";
} Else {
echo "Found Nothing for Store# $Store <br>";
}
Echo "Finished!";
i5_close( $conn ) || print ("FAIL : Failed to disconnect from server :$i5_server_ip");
?>
--The basic flow of Data Retrieval is:
Assign Query ( $qry above )
Prepare the Query ( i5_prepare )
Bind the Parameters *if needed* (i5_bind_param)
Execute the Query (i5_execute)
Fetch the data (i5_fetch_assoc)
** Side Note ** from past experience, I like the ASSOC better than ARRAY on the Fetch due to the clean look on using what was retrieved. At that point, you can use the $row['VARNAME'] format so it's easier to debug and or maintain down the road. (But, that's just me)
--Notice the use of Parameters. This allows for building a form, prompting for search criteria and never having to change the QRY statement. They are bound (in order) by the i5_bind_param function. Not a requirement, but does come in handy....
This is just a start, but it does allow me to start moving in quite a few different directions. Mainly ... the one that *hopefully* pushes my company to use this moving forward!
PS: Thanks to those websites that help with syntax and flow... too many to list -- but, I have no problems recognizing those who help others!
Until Next time...
Comment