You are here: Home
PHP/PostgreSQL: Create Recordset & Display PDF Print E-mail
Development - PHP
Written by Rick   
Monday, 25 January 2010 12:00

Creating a recordset and displaying data from a PostgreSQL table using PHP;

Making the connection:

$DB_HOST="hostname";
$DB_NAME="databasename";
$DB_USER="username";
$DB_PASSWORD="password";


$psql="Select DISTINCT fieldname FROM table";
$const = "host=".$DB_HOST." dbname=".$DB_NAME." user=".$DB_USER." password=".$DB_PASSWORD."";
$pcon=pg_connect($const);
if (!$pcon) {
echo "<script type=\"text/javascript\">alert(\"Unable to connect to PostgreSQL Server!\")</script><script type=\"text/javascript\">history.back()</script>";
}else{
$getRS = pg_exec($pcon,$psql);
}

pg_close($pcon);


Create the recordset and display:

$getRS = psqlSelectRS($psql);
$rows=pg_num_rows($getRS);

for ($i=0; $i<$rows; $i++) {
$row_getRS=pg_fetch_row($getRS, $i);
echo "Row Value: ".$row_getRS[0]."<br />;
}

pg_free_result($getRS);

 
SSH: Stop Asking to Add New Hosts PDF Print E-mail
Tech Notes - Linux
Written by Rick   
Tuesday, 29 December 2009 11:33

An annoying little thing. When connecting via SSH to another machine for the first time SSH always prompts;

---
The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established.
RSA key fingerprint is ..............
Are you sure you want to continue connecting (yes/no)?
---

Typing "yes' each time can be pain in the butt. There is a way to change that behavior but, some believe it exposes you to a Man-in-the-middle attack.You've been advised!

I've changed settings in most of my /etc/ssh/ssh_config files to stop the machine from begging for a "yes" response, to just automatically adding the new host to the known_hosts file. I did that by changing the parameter value of StrictHostKeyChecking to "no" and restarting the SSH service.

Note: This does not stop SSH from checking that the host exists in the known_hosts file. It simply adds new hosts to the file without prompting.

 
PHP CLI: Rsync Script PDF Print E-mail
Tech Notes - Linux
Written by Rick   
Wednesday, 23 December 2009 17:01

Here's a handy script to run rsync from the command-line that prompts for source and destination paths;

#! /usr/bin/php

<?php
## Control CLI parameters
if (($argv[1]=="") OR ($argv[2]=="")) {
echo "Options not specified.\r\n";
echo "Program Usage: ";
echo $argv[0]." <i.e.: /source/path> <i.e.: /destination/path>\r\n\r\n";
exit;
}else{
$srcpath=$argv[1];
$dstpath=$argv[2];
}

$starttime=date('G:i:s', strtotime('now'));

echo "Starting rsync...\r\n";
$retval=system("sudo rsync -avrl --delete ".$srcpath." ".$dstpath, $retval);
if (!$retval==false) {
echo "Backup from ".$srcpath." to ".$dstpath." is complete!\r\n\r\n";
}else{
echo "Backup from ".$srcpath." to ".$dstpath." FAILED!\r\n\r\n";
}

$endtime=date('G:i:s',strtotime('now'));


echo "\r\nStart time - ".$starttime."\r\n";
echo "End time - ".$endtime."\r\n\r\n";
echo "Script complete!\r\n";

?>

Note:

  • The sudo command in the system call allows the script to be used to sync root user files. This can be removed if that behavior is not desired.
  • The script also utilizes the --delete feature of rsync to remove files in the destination that do not exist in the source. Evaluate that behavior for your application as well.
 
PHP CLI: Virtual Box Startup Script PDF Print E-mail
Development - PHP
Written by Rick   
Tuesday, 10 November 2009 18:00

Administrators are often called upon to write scripts to accomplish tasks. I've been playing a lot with php cli scripting lately and had a need to create a script to startup a VirtualBox VM from the command line. Here's what it looks like;

#!/usr/bin/php
<?php
if ($argv[1]=="") {
echo "Options not specified.\n\r";
echo "Usage: ";
echo $argv[0]." <vmname>\n\r\n\r";
exit;
}else{
$vm=$argv[1];
system("VBoxManage vmstatistics ". $vm,$retval);
if ($retval==1) {
echo "Starting Virtual Machine ".$vm."\r\n";
#system("VBoxVRDP -startvm ".$vm,$rval);
system("VBoxManage startvm ".$vm." --type headless",$rval);
}else{
echo $vm." appears to be running already!\r\n";
exit;
}
}
?>

I found using VboxVRDP and VBoxHeadless left the script incomplete and open even after shutting down the virtual machine. I've left a commented line with the VBoxVRDP startup statement for your testing purposes.

 
Windows 7 Release Underwhelms PDF Print E-mail
IMHO - General
Written by Rick   
Friday, 23 October 2009 18:00

Where was the great fanfare associated with past Windows releases? No news stories about people standing in-line at midnight to get their copy? Did people stand in-line to get a copy on the first day of release? If they did, it must not have been news worthy, or perhaps I just missed it. I did however, notice the news about Windows competitors. Apparently Apple released a new ad campaign targeting Windows 7 and IBM revved up it's bid to get Linux on the deskptop. Ubuntu, I'm sure with the Windows release in-mind, released the RC version of 9.10 code-named Karmic Koala (Who comes up with these names?).

Metaphorically speaking, these are direct shots at Microsoft. Unfortunately, the view finder seems a little off as none, independently, will do major damage to Windows now or in the near future. Though each time these shots are fired, the bullets get bigger and the target become clearer. Window's won't be brought down with a single shot. It'll take time and effort to chip-away at the monolith. With each year that passes, Microsoft loses a little.

I can't "sing the praises" of free operating systems loud enough (no one wants to hear me sing anyway) a.k.a. Linux. I'm empowered and unfettered without Microsoft Windows or Apple's OS X. I can't help but feel that all those years I was a Windows fan went to waste.

 
<< Start < Prev 1 2 3 Next > End >>

Page 1 of 3