Some basic PHP calls for use in Delphi for PHP or pure 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’);
















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
Comment by Stuart Kelly — April 1, 2007 @ 7:48 pm
Done Stu, and thanks for the Tip!
Comment by Brian — April 1, 2007 @ 9:32 pm
Excellent! Thanks for the post -- I will cross post this article on my blog as well, as I personally find it helpful.
Comment by OneNerd — April 1, 2007 @ 9:48 pm
[...] 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): [...]
Pingback by Firebird News » Some basic PHP calls for use in Delphi for PHP or pure PHP — April 4, 2007 @ 10:25 am
[...] Some excellent PHP code snippets at the code cave blog to use in your Delphi for PHP coding: http://www.thecodecave.com/article363 [...]
Pingback by Some useful PHP Code Snippets : OneNerd’s Software Company — April 21, 2007 @ 5:11 pm