You are here: Home Development PHP
PHP
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);

 
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.

 
PHP CLI: Simple Process Control in Linux with PCNTL_EXEC PDF Print E-mail
User Rating: / 1
PoorBest 
Development - PHP
Written by Rick   
Friday, 15 May 2009 00:00

I've been working on a project using php executed from the command line. The project downloads files via FTP from several sources, renames the files and tosses the files into a new directory structure. I never thought I'd find a legitmate reason to create a "file scrounger".

Throughout development I've been executing the script from the command line to test and debug. Happily building the app step by step. Once it was complete I thought I'd just be able to execute it from a cron job on my Linux box and be done with it. Boy, was I wrong!!!

Read more...
 
PHP: Word Popularity/Density Script PDF Print E-mail
Development - PHP
Written by Rick   
Wednesday, 10 December 2008 10:49

I found this at Bit Repository. Decided to add it here for posterity.

Function:

Read more...
 
PHP: Display Row (Field) Names in MySQL Database Table PDF Print E-mail
User Rating: / 3
PoorBest 
Development - PHP
Written by Rick   
Monday, 14 July 2008 17:00

On occassion we need to get the Row names in a table. The following code snippet shows how to connect to the database and display all the Row names in the database table.

Read more...
 
PHP: Send 404 Error Header PDF Print E-mail
Development - PHP
Written by Rick   
Friday, 06 June 2008 09:28

To return the proper header information in a file used as a 404 error page, enter the following line at the beginning of the document (Yes, before <!DOCTYPE> and <html> tags);

<php header("HTTP/1.0 404 Not Found"); ?> 

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

Page 1 of 2