Some basic PHP calls for use in Delphi for PHP or pure PHP
Ξ April 1st, 2007 | → | ∇ Delphi for PHP |
I was doing some coding today and couldn’t find some routines I’ve used often in the past. Since I had to search for them, obeying my rule, they get posted here. Maybe they can be of use to others. These are examples I’ve written and once I’ve collected and customized. I’ve not put comments in most of these routines, sorry.
(THIS IS A LIVING POST AND WILL CHANGE PERIODICALY AS I DIG UP OTHER COMMON ROUTINES)
Clean an array of all vulnerabilities:
-
function strip_and_slash_deep($value) {
-
}
Use:
-
-
$protected_post_vars = strip_and_slash_deep($_POST);
My print_r replacement to print an array in full depth:
-
function print_array($array) {
-
{
-
{
-
{
-
{
-
}
-
}
-
else
-
{
-
}
-
}
-
}
-
}
Basic structure for using PHP to connect to an interbase or firebird database:
-
function ib_execsql ($sql) {
-
$fulldbpath = “localhost:d:\blah.gdb”;
-
$username = “sysdba”;
-
$password = “masterkey”;
-
$ib = ibase_connect ($fulldbpath, $username, $password,‘NONE’, ‘100′, ‘1′);
-
$result = @ibase_query ($ib, $sql);
-
if ($result===false) echo “<hr/>Error ‘”.ibase_errmsg().“‘ while executing ‘”. $sql.“‘<hr/>”;
-
while ($row = ibase_fetch_row ($result)) $aresult[] = $row;
-
ibase_close ($ib);
-
return $aresult;
-
}
use:
-
$array = ib_execsql(“select * from whatever”);
-
print_array($array);
Run a single query across many databases on the same MySQL server:
-
function execdbsql ($databasename) {
-
if (!$link) {
-
}
-
-
-
-
if (!$result) {
-
return; // Don’t error out just skip this database.
-
}
-
-
-
}
-
-
echo “Values:<br/>”;
-
-
execdbsql (‘firstdb’);
-
-
execdbsql (’seconddb’);
-
-
execdbsql (‘thirddb’);
on April 1st, 2007 at 7:48 pm
May I suggest that the example should be
$protected_post_vars = strip_and_slash_deep($_POST);Since $HTTP_POST_VARS is depreciated in PHP 5 and will be removed in PHP 6
on April 1st, 2007 at 9:32 pm
Done Stu, and thanks for the Tip!
on April 1st, 2007 at 9:48 pm
Excellent! Thanks for the post -- I will cross post this article on my blog as well, as I personally find it helpful.
on April 4th, 2007 at 10:25 am
[...] I’ve used often in the past. Since I had to search for them, obeying my rule, they get posted here. Maybe they can be of use to others. Permalink | Share (digg, etc): [...]
on April 21st, 2007 at 5:11 pm
[...] Some excellent PHP code snippets at the code cave blog to use in your Delphi for PHP coding: http://www.thecodecave.com/article363 [...]