[Top] [Prev] [Next] [Last]
|
|
Chapter 11PHP Embedded Scripting
- embed C-like scripts in your HTML files
- embed SQL queries in your HTML files for querying an mSQL, mysql, Solid, Sybase, Oracle, Illustra, Adabas, Postgres95, or PostgreSQL database
- automatically generate footers with access information
- control access via a built-in, Web-based configuration screen
- support RFC-1867-compliant user file uploads
By default, the PHP module is compiled into the server without support for databases, access control, page logging, or file uploads. To recompile it with one or more of these features, see "PHP Configuration" on page 11-2.
This chapter explains the PHP scripting mechanism, including
- PHP configuration
- scripting rules
- user file uploads
- PHP security
- special topics
- PHP internal functions
The PHP Web site at http://php.iquest.net/ has additional information, including extra examples, archives, access to the PHP mailing list, and instructions for creating your own PHP functions.
To process HTML through PHP
- Add the following line to httpd.conf:
AddType application/x-httpd-php .php
- Give the .php filename extension to any file you want to process with PHP.
By default, httpd.conf contains the following line:
AddType application/x-httpd-php .php
This line is necessary for Stronghold to recognize and process PHP files.
If you do not want footers appended to your .php files, you can turn them off globally or on a per-file basis. To turn them on or off globally, use the phpShowInfo configuration directive. To turn them off in individual files, add this tag:
<?setshowinfo(0)>
PHP Configuration
- database support for mSQL, mysql, Solid, Sybase, Oracle, Illustra, Adabas, Postgres95, or PostgreSQL
- access control
- page logging
- file upload support
In order to reconfigure the PHP module to implement these special features, you must
- reconfigure the source files,
- recompile the PHP module, and
- recompile Stronghold with the new PHP module.
To reconfigure PHP
- Switch to the PHP source directory:
# cd ServerRoot/src/php
- Run the install script:
# ./install
- Enter "Y" if you have mSQL or "N" if you do not.
- Enter "Y" if you have Sybase libraries or "N" if you do not.
- Enter "Y" if you have Postgres or "N" if you do not.
- Enter "Y" if you have mysql or "N" if you do not.
- Enter "Y" if you have Solid or "N" if you do not.
- Enter "Y" if you have Oracle or "N" if you do not.
- Enter "Y" to compile PHP as an Apache module.
- Enter "Y."
- Enter "Y."
The script asks whether your operating system supports ELF dynamic loading.
- Enter "Y" if you are running Linux with ELF dynamic loading support or "N" if you are not.
The script prompts you for the path to Stronghold's include or source directory.
- Enter the path to Stronghold's source directory.
- Enter "Y" to enable access control or "N" to disable it.
If you enter "Y," you must next enter the path to the directory you want to use for access control.
- Enter "Y" to enable page logging or "N" to disable it.
If you enter "Y," you must next enter
- "D" to store the logs in DBM format or "M" to store them in mSQL format
- the path to the directory where you want to store your PHP page logs
- Enter "Y" to enable file upload support or "N" to disable it.
- If you would like to include additional .h files, enter the paths to their directories.
The program includes all files in the directories you specify.
- If you would like to include additional libraries, enter the paths to their directories.
NOTE: Watch for error messages during this phase. When an error occurs, the script also gives instructions for rectifying the problem.
- Enter "Y" to use the Posix regex library that comes bundled with PHP or "N" to use your own.
- Switch to the PHP src/ directory:
# cd src
- Run make:
# make
- Check your Configuration file to make sure it includes these three lines:
Rule WANTHSREGEX=yes
EXTRA_LIBS= . . . -lphp -lm . . .
Module php_module mod_php.o
- Recompile Stronghold as described in "Recompiling Stronghold" on page 8-9.
The PHP Scripting Language
This section describes the elements of PHP scripts, including their syntax and available commands. For an alphabetical list of all internal PHP functions, see "Internal Function Reference" on page 11-17.
Syntax
- Variables are preceded by a dollar sign ($).
- As in HTML, extra white space is ignored.
- Comments open with /* and close with */.
- Instructions are separated by semicolons (;).
- Functions are immediately followed by a comma-delimited set of parameters in parentheses, if parameters apply. For example:
fopen("/home/rasmus/file.txt","r");
- Commands are followed by a space and a comma-delimited set of parameters, if any apply.
Thus, a valid PHP string might look like this:
<? $a = 5; echo $a /* sample string */ >
Control Commands
PHP supports the following commands for guiding the control flow through a file:
- if (conditional)
- else
- elseif (conditional)
- endif
- switch (expression)
- endswitch
- case expression
- default
- break
- while
- endwhile
- include
- ++ (increment)
- -- (decrement)
- exit
NOTE: This loop behavior deviates from C, where variables can be incremented or decremented before or after an operation.
<?
$a=0;
switch($a);
case 1;
echo "a is 1";
break;
case "hello";
echo "a is hello";
break;
default;
echo "a is unknown";
break;
endswitch
>
In addition, PHP supports these C-like conditional symbols:
Conditional Description = = Tests for equality. != is not equal to > is greater than < is less than >= is greater than or equal to <= is less than or equal to && conditional AND || conditional OR <?
if($a==5 && $b!=0 );
$c = 100 + $a / $b;
endif;
>
<?
if($a==5 && $b!=0) {
$c = 100 + $a / $b;
}
>
Mathematical Expressions
Operator Description + Addition - Subtraction * Multiplication / Division % Modulus += Incremental addition -= Incremental subtraction & Bit-wise AND | Bit-wise OR
Regular Expressions
PHP includes seven internal functions for regular expressions:
- EReg()
- ERegi()
- EReg_Replace()
- ERegi_Replace()
- Reg_Match()
- Reg_Replace()
- Reg_Search()
Escape Characters
PHP supports the following escape sequences in any quoted string argument:
Escape Sequence Description \a Bell \b Backspace \n Line feed \r Carriage return \t Tab \nnn Octal character code \xxx hexagonal character code
Variables
PHP variables are prepended with dollar signs ($) and can take three types of values:
- integers, such as
$a = 5
- double precision floating point values, such as
$a = 5.7
- character strings, such as
$a = "hello world"
$a = 1
$b = "1"
$d = $a + $b
NOTE: For more complex expressions, you may need to force variables to conform to a certain type. To do so, use the function.
$a = "hello"
$$a = "world"
echo "$a $$a"
echo "$a $hello"
<?$a[0] = "hello world">
<?$a = 5>
<?$a[0] = 5>
$a[] = "hello"
$a[] = "world"
exist, then PHP interprets them as
$a[0] = "hello"
$a[1] = "world"
$a = $b;
You can also append one array to another like this:
$a[] = $b;
- Global: A global variable is declared outside a function. It can be used in any function within the same script, but must be declared global inside any function in which it is used. For example:
$a=1;
$b=2;
Function Sum $first,$second (
global $a,$b;
$b = $a + $b;
);
Sum();
echo $b;
- Local: A local variable is declared within a function and exists only for that function. Unless it is declared otherwise, any variable called by a function is local. For example:
$a=1; /* global scope */
Function Test (
$a=5; echo $a; /* reference to local scope variable */
);
Test();
- Static: A static variable has a local function scope, but retains its value when the program leaves the function. For example, consider a counting function like this one:
Function Test (
static $a=0;
echo $a;
$a++;
);
Function Test (
static $count=0;
$count++;
echo $count;
if($count < 10) {
Test();
}
);
User-Defined Functions
<?
Function Test (
echo "This is a test\n";
);
>
<?
Test();
>
<?
Function Sum $a,$b,$c (
return ($a+$b+$c);
);
echo Sum($a,$b,$c);
>
User File Uploads
<FORM ENCTYPE="multipart/form-data" ACTION="URL" METHOD=POST>
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000">
Send this file: <INPUT NAME="userfile" TYPE="file">
<INPUT TYPE="submit" VALUE="Send File">
</FORM>
Use the phpUploadTmpDir directive to set the temporary directory for all user-uploaded files.
PHP and Security
Basic HTTP Authentication
NOTE: Although basic authentication provides some security, it also causes unencrypted usernames and passwords to pass from the client to Stronghold, allowing eavesdroppers to obtain them. If you use basic authentication, confine it to SSL-encrypted transactions.
For example, the following script fragment invokes basic authentication, then prints the user input:
<?
if(!$PHP_AUTH_USER) {
Header("WWW-authenticate: basic realm=\"My Realm\"");
Header("HTTP/1.0 401 Unauthorized");
exit;
} else {
echo "Hello $PHP_AUTH_USER.<P>";
echo "You entered $PHP_AUTH_PW as your password.<P>";
}
>
GET and POST
www.host.com/example.php?REMOTE_HOST=some.bogus.com
<?SecureVar(".*data.*")>
This example secures any variable that contains the string "data."
Special Notes
Multiple-Selection Lists
<SELECT NAME="listname" MULTIPLE>
To solve this problem, use an array as the list name:
<SELECT NAME="listname[]" MULTIPLE>
Image Form Buttons
HTML allows you to use images as form submission buttons, using a tag like this one:
<INPUT TYPE=IMAGE SRC=image.gif NAME=submit>
Self-Referential URLs
Internal Function Reference
This section provides a quick reference to all internal PHP functions.
Abs(arg)
Abs returns the absolute value of arg.
Ada_Close(connection_id)
This function is only available if Adabas support has been enabled in PHP.
$connection = Ada_Connect(data-source-name, username, password)
This function is only available if Adabas support has been enabled in PHP.
$result = Ada_Exec(connection_id, query_string)
Ada_Exec() sends an SQL statement to the Adabas server specified by connection_id. The connection_id must be a valid identifier that was returned by Ada_Connect() or the special value 0. If connection_id is 0, Ada_Exec() tries to establish or use a connection with the parameters given by the configuration directives phpAdaDefDB, phpAdaUser, and phpAdaPW.
This function is only available if Adabas support has been enabled in PHP.
Ada_FetchRow(result_id [,row_number])
This function is only available if Adabas support has been enabled in PHP.
Ada_FieldName(result_id, field_number)
This function is only available if Adabas support has been enabled in PHP.
Ada_FieldNum(result_id, field_name)
This function is only available if Adabas support has been enabled in PHP.
Ada_FieldType(result_id, field_name|field_number)
This function is only available if Adabas support has been enabled in PHP.
Ada_FreeResult(result_id)
This function is only available if Adabas support has been enabled in PHP.
Ada_NumFields(result_id)
This function is only available if Adabas support has been enabled in PHP.
Ada_NumRows(result_id)
This function is only available if Adabas support has been enabled in PHP.
Ada_Result(result_id, field name|index)
This function is only available if Adabas support has been enabled in PHP.
Ada_ResultAll(result_id [,format])
<table format>
This function is only available if Adabas support has been enabled in PHP.
AddSlashes(arg)
This function escapes any "$," "\," or "'" with a backslash if MAGIC_QUOTES is set. See also the StripSlashes(arg) function.
ARSort(array)
ASort(array)
NOTE: If you are going to sort a non-associative array, you should use the Sort(array) function.
BinDec(binary_string)
BinDec returns the decimal equivalent of a binary number specified by the binary_string argument. The largest convertible number is 31 bits long, or 4294967295 in decimal. See also the DecBin(number) function.
ChDir(dir)
ChDir changes the current working directory to the directory specified by dir.
ChGrp(file,group)
ChGrp changes the group ID of the specified file to group.
ChMod(file,perms)
Chop(string)
ChOwn(file,owner)
ChOwn changes the owner of file to owner.
NOTE: This function works only if Stronghold is running as root. Since running the server as root presents a security risk, avoid this function.
Chr(arg)
Chr returns the ASCII character represented by the integer argument.
ClearStack()
ClearStatCache()
closeDir()
This function closes a directory opened using the openDir(directory) function.
Cos(arg)
This function returns the cosine of arg in radians. See also Sin(arg) and Tan(arg).
Count(array)
Crypt(string,[salt])
For more information about crypt(), see your UNIX man page.
Date(format,time)
PHP prints any unrecognized character verbosely.
dbList()
dbList() prints information about the DB support compiled into PHP.
dbmClose(file)
dbmDelete(file,key)
dbmDelete() deletes the key/content pair specified by key from the file.
dbmExists(file,key)
dbmExists() returns 1 if the key exists in the file, and 0 otherwise.
dbmFetch(file,key)
dbmFetch() returns the content string associated with the given key.
dbmFirstKey(file)
dbmFirstKey() returns the first key in the DBM file. The order depends on hash table values calculated within the DBM implementation, and is therefore beyond the control of PHP. You can use the Sort(array) function to sort arrays of data from the DBM file.
dbmInsert(file,key,content)
dbmNextKey(file,key)
dbmOpen(file,mode)
dbmOpen() opens a DBM file. File is the full path to the DBM file, and mode is the file open mode:
- r: read
- n: new (implies write) and read
- w: write
For more information on DBM files, see your UNIX man pages or obtain GNU's gdbm from ftp://prep.ai.mit.edu/pub/gnu.
dbmReplace(file,key,content)
dbmReplace() resembles the dbmInsert(file,key,content) function, except that if the key already exists, the old content string is replaced with the new.
DecBin(number)
DecBin() returns a string containing a binary representation of the given number. The largest convertible number is 31 bits long, or 4294967295 in decimal. See also the BinDec(binary_string) function.
DecHex(number)
DecHex() converts a decimal number to a hexadecimal string. See also the HexDec(hex_string) function.
DecOct(number)
DecOct() converts a decimal number to an octal number. See also OctDec(octal_number).
doubleval(variable)
doubleval() returns the double (floating point) value of variable. See also the strval(variable) and intval(variable) functions.
Echo [format_string] expression [, expression [,...]]
Echo is not properly a function because its arguments are not bracketed. It is a command that displays the results of other PHP functions or variables. See "Escape Characters" on page 11-9 for a list of the special characters it supports.
The types of the expressions are not relevant. PHP automatically converts the expressions to the appropriate types as specified by the format_string, if one is present. If you want to format something and assign the formatted string to a variable instead of displaying it, use the Sprintf(format,arg) function.
PHP supports the following conversion values for format_string:
The following flags are also valid:
PHP ignores any extra arguments that are not required by format_string.
End(variable)
<?
Reset($array);
$first_key = key($array);
End($array);
$k = key($array);
while($k != $first_key);
echo $array[$k];
prev($array);
$k = key($array);
endwhile;
echo $array[$k];
>
See also Reset(variable) and Prev(variable).
ereg(expr,arg[,regex])
ereg() returns a non-zero value if the argument string matches the regex. For example, the condition
<?if (ereg("^This.*", "This is an example string")>
For information about regular expressions, see "Regular Expressions" on page 11-9.
eregi(expr,arg[,regex])
eregi() is identical to the ereg() function, except that the regular expression is case-insensitive.
ereg_replace(regex,replace,arg)
ereg_replace(" ","-","This is an example string")
For more information on regular expressions, see "Regular Expressions" on page 11-9.
eregi_replace(regex,replace,arg)
eregi_replace() is identical to the ereg_replace() function except that regex is case-insensitive.
EscapeShellCmd(string)
EscapeShellCmd() escapes any characters in a string that might be used to trick a shell command into executing arbitrary commands. Use this function to sterilize any data originating with user input before PHP passes it to the Exec(command_string [, array [,return_var]]) or System(command_string [,return_var]) functions. For example:
<?system(EscapeShellCmd($cmd))>
Eval(string)
$a = "echo phpversion();";
eval($a);
eval("echo phpversion();");
eval("\$a=1; echo \$a;");
Exec(command_string [, array [,return_var]])
Exec() executes the given UNIX command_string, but generates no output. Instead, it returns the last line from the result of the command. If you need to execute a command and pass all the data from the command directly back without any interference, use the PassThru(command_string [,return_var]) function.
NOTE: If you allow PHP to pass data originating with user input to the Exec function, then you should use the EscapeShellCmd(string) function to make sure that users cannot execute commands.
See also the System(command_string [,return_var]) function.
Exit
The Exit command terminates parsing immediately after it is parsed.
Exp(arg)
Exp() returns e raised to the power of arg. See also pow(x,y).
fclose($fd)
fclose() closes a file opened by $fp = fopen(file,mode). The argument is a file pointer index as returned by fopen().
feof($fd)
fgets($fd,bytes)
fgets() reads a line from a file opened by $fp = fopen(file,mode). The arguments are a file pointer index as returned by fopen() and the maximum number of bytes to read. Reading ends when the maximum number of bytes have been read, or when an end-of-line has been reached. This is similar to the C fgets() call. See also fputs(fp,string).
fgetss($fd,bytes)
$array = File(file)
fileAtime(file)
fileCtime(file)
fileCtime() returns the time of last status change. If the file does not exist, or if it cannot be accessed, this function returns -1. If the file is repeatedly accessed and is dynamic, be sure to use ClearStatCache() to reset the cache.
fileGroup(file)
fileGroup() returns the group ID of the owner of the file. If the file does not exist, or if it cannot be accessed, this function returns -1. If the file is repeatedly accessed and is dynamic, be sure to use ClearStatCache() to reset the cache.
fileInode(file)
fileInode() returns the file's inode. If the file does not exist, or if it cannot be accessed, this function returns -1. If the file is repeatedly accessed and is dynamic, be sure to use ClearStatCache() to reset the cache.
fileMtime(file)
fileMtime() returns the time of last data modification. If the file does not exist, or if it cannot be accessed, this function returns -1. If the file is repeatedly accessed and is dynamic, be sure to use ClearStatCache() to reset the cache.
fileOwner(file)
fileOwner() returns the UID of the owner of the file. If the file does not exist, or if it cannot be accessed, this function returns -1. If the file is repeatedly accessed and is dynamic, be sure to use ClearStatCache() to reset the cache.
filePerms(file)
filePerms() returns the permission bits of the file. This is the st_mode field of the UNIX C stat structure. If the file does not exist, or if it cannot be accessed, this function returns -1. If the file is repeatedly accessed and is dynamic, be sure to use ClearStatCache()) to reset the cache.
fileSize(file)
fileSize returns the size of the file in bytes. If the file does not exist, or if it cannot be accessed, this function returns -1. If the file is repeatedly accessed and is dynamic, be sure to use ClearStatCache() to reset the cache.
fileType(filename)
This returns the type of the file filename. The return values are one of the following:
Value Description dir directory file regular file fifo fifo special char character special block block special link symbolic link
Flush()
The Flush() function is used to flush the output buffer.
$fp = fopen(file,mode)
- r
- r+
- w
- w+
- a
- a+
$fp = fopen("/home/rasmus/file.txt","r");
See the UNIX man page on the fopen() call for more information. See also the
fp = popen(command,mode) and the fclose($fd) function descriptions.
ForceType(variable,type)
ForceType() sets the type flag for the variable. The value for type can be one of the following:
- an integer
- a floating point value
- string
See also intval(variable), doubleval(variable), strval(variable).
FPassThru(fp)
fputs(fp,string)
fputs() writes a line to a file opened by $fp = fopen(file,mode). The arguments are a file pointer index as returned by fopen() and the string to write. The string argument may contain escape characters. See also fgets($fd,bytes).
fseek(fp,pos)
fseek() positions a file pointer identified by the return value of the $fp = fopen(file,mode) call. The file pointer is positioned at the beginning of the file, plus the offset specified by the pos argument. See also pos = ftell(fp) and rewind($fd).
fp = fsockopen(hostname,port)
fsockopen() opens a socket connection and returns a file pointer index. This file pointer index can be used by fgets($fd,bytes), fputs(fp,string), and fclose($fd). Return values are
- -3 if the socket couldn't be created
- -4 if the DNS lookup on the hostname failed
- -5 if the connection was refused or it timed out
- -6 if the actual fdopen() call failed
- -7 if the setvbuf() call failed.
pos = ftell(fp)
ftell() returns the position of a file pointer identified by the fp argument, which is the return value of the fopen() call. The position can later be used as an argument for fseek(). See also fseek(fp,pos) and rewind($fd).
getAccDir()
GetEnv(string)
getHostByName(domain_name)
getHostByName() converts the given domain_name into an IP number.
getHostByAddr(IP_address)
GetImageSize(filename)
- width
- height
- type
- a string containing "width=x height=y"
This string can be used directly in an HTML <IMG> tag, like this:
<?
$result = GetImageSize("img/flag.jpg");
>
<IMG SRC="img/flag.jpg" ?echo $result[3]> >
NOTE: The GD image library is not needed to use this function.
getLastAccess()
getLastAccess() returns the date and time, in UNIX time format, of the last time the current page was accessed. You can pass this value to the Date(format,time) function for formatting. This function is only available if PHP is compiled with access logging enabled, as described in "PHP Configuration" on page 11-2.
getLastbrowser()
getLastBrowser() returns the identification string of the browser last used to access the current page. This function is only available if PHP is compiled with access logging enabled, as described in "PHP Configuration" on page 11-2.
getLastEmail()
getLastEmail() returns the email address of the last user to access the current page. This function is only available if PHP is compiled with access logging enabled, as described in "PHP Configuration" on page 11-2.
getLastHost()
getLastHost() returns the hostname of the last user to access the current page. This function is only available if PHP is compiled with access logging enabled, as described in "PHP Configuration" on page 11-2.
getLastMod()
getLastMod() returns the date and time, in UNIX time format, of the last time the current page was modified. You can pass this value to the Date(format,time) function for formatting. This function is only available if PHP is compiled with access logging enabled, as described in "PHP Configuration" on page 11-2.
getLastref()
getLastRef() returns the URL of the referring document of the access of the current page. This function is only available if PHP is compiled with access logging enabled, as described in "PHP Configuration" on page 11-2.
getLogDir()
getMyInode()
getMyInode() returns the numerical inode of the current HTML file.
getMyPid()
getMyPid() returns the current process ID of the PHP parsing process.
getMyUid()
getMyUid() returns the numerical user ID of the owner of the current HTML file.
getRandMax()
getRandMax() returns the maximum random number that the Rand() function returns.
NOTE: If the value returned does not seem accurate, look at the ServerRoot/src/php/src/php.h source file in the PHP distribution for more information.
getStartLogging()
getToday()
getToday() returns the total number of hits the current page has received since midnight local time. This function is only available if PHP is compiled with access logging enabled, as described in "PHP Configuration" on page 11-2.
getTotal()
GetType(variable)
- an integer
- a floating point value
- a string
See also the SetType(variable,type) function.
gmDate(format,time)
gmDat() is identical to the Date(format,time) function except that it uses Greenwich Mean Time instead of the current local time.
Header("header_string")
The Header() command is used at the top of an HTML file to send raw HTTP header strings. See the HTTP Specification for more information on raw HTTP headers. Remember that the Header() command must be used before any actual HTML tags or PHP Echo() commands.
HexDec(hex_string)
HexDec() converts a hexadecimal string to a decimal number. See also the DecHex(number) function.
HtmlSpecialChars(string)
ImageSX(image)
ImageSX() returns the width of the image.
ImageSY(image)
ImageSY() returns the height of the image.
Include(filename)
Since the PHP module performs full PHP parsing on the included file, you can also use the Include() command to include your stock PHP scripts, like a primitive shared library. You can also use the phpIncludePath directive to set the path to your script library directory, then refer to scripts by filename only rather than by full paths.
intval(variable)
Intval() returns the long integer value of variable. See also the strval(variable) and doubleval(variable) functions.
IsSet(variable)
The IsSet() function returns 1 if the variable is defined, and 0 if it is undefined.
Key(variable)
Key() returns the key of the current array item. The current item is determined by the position of the array pointer for the variable. You can manipulate this array pointer with the Reset(variable), End(variable), Next(variable), and Prev(variable) functions. This function is mainly used for determining the key value for an item in an associative array, although it works for normal arrays as well.
Link(target,link)
Link() creates a hard link. See the Symlink(target,link) function for creating symbolic (soft) links. See also ReadLink(path) and LinkInfo(path) functions.
LinkInfo(path)
Log(arg)
Log() returns the natural logarithm of arg.
Log10(arg)
Log10() returns the base-10 logarithm of arg.
LogAs(filename)
Max(array)
Md5(string)
Md5 returns the MD5 hash of a string value.
$connection = mi_Connect(database, username, password)
This function is only available if Illustra support has been enabled in PHP.
mi_DBname(connection_id)
This function is only available if Illustra support has been enabled in PHP.
$result = mi_Exec(connection_id, query_string)
mi_Exec() sends an SQL statement to the Illustra database specified by the connection_id. The connection_id must be a valid identifier that was returned by $connection = mi_Connect(database, username, password). The return value of this function is an identifier to be used to access the results from other Illustra functions. This function returns -1 on error.
This function is only available if Illustra support has been enabled in PHP.
mi_FieldName(connection_id, result_id, field_number)
This function is only available if Illustra support has been enabled in PHP.
mi_FieldNum(connection_id, result_id, field_name)
This function is only available if Illustra support has been enabled in PHP.
mi_NumFields(connection_id, result_id)
mi_NumFields() returns the number of fields (columns) in an Illustra result. The argument is a valid result identifier returned by $result = mi_Exec(connection_id, query_string). This function returns -1 on error.
This function is only available if Illustra support has been enabled in PHP.
mi_NumRows(connection_id, result_id)
mi_NumRows() returns the number of rows in an Illustra result. The argument is a valid result identifier returned by $result = mi_Exec(connection_id, query_string). This function returns -1 on error.
This function is only available if Illustra support has been enabled in PHP.
mi_Result(connection_id, result_id, row_number, field_name/field_index)
mi_Result() returns values from a result identifier produced by $result = mi_Exec(connection_id, query_string). The row_number and field_name specify what cell in the table of results to return. Row numbering starts from 0. Instead of naming the field, you may use the field_index as an unquoted number. Field indices start from 0.
This function is only available if Illustra support has been enabled in PHP.
Microtime()
Min(array)
MkDir(directory,mode)
MkDir() creates a directory. The mode parameter must be given in octal notation.
MkTime(hour,min,sec,mon,day,year)
MkTime(hour,min,sec)
MkTime(mon,day,year)
$result = msql($database,$query)
msql() sends an mSQL query. Arguments are the database name and the query string. For example:
<?msql("MyDatabase" , "select * from table")>
The function returns -1 if an error occurs. A string describing the error is placed in $phperrmsg, and unless the function was called as @msql(), then this error string is also printed. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_Close()
msql_connect($hostname)
<?msql_connect("localhost")>
This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_CreateDB($database)
msql_CreateDB() creates the given database. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_dbName($result,$i)
msql_dbName() returns the database name stored in position $i of the result pointer returned from the $result = msql_ListDBs() function. You can use the msql_NumRows($result) function to determine how many database names are available. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_DropDB($database)
msql_DropDB() deletes the given mSQL database. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
NOTE: Use this with caution, as all data in the database will be lost.
msql_FieldFlags($result,$i)
- "not null"
- "primary key"
- a combination of the two
- an empty string
This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_FieldLen($result,$i)
msql_FieldLen() returns the length of the specified field. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_FieldName($result,$i)
msql_FieldName($result,2);
returns the name of the second field in the result associated with the result identifier. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_FieldType($result,$i)
- "int"
- "char"
- "real"
This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_FreeResult($result)
You only need to call msql_FreeResult() if you are concerned about using too much memory while your script is running. It causes all result memory to be freed automatically when the script is finished. However, if you are sure you will not need the result data later in a script, you may call msql_FreeResult() with the result identifier as an argument, and the associated result memory is freed. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
$result = msql_ListDBs()
msql_ListDBs() returns a result pointer containing the databases available from the current mSQL daemon. Use the msql_dbName($result,$i) function to traverse this result pointer. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
$result = msql_Listfields($database,$tablename)
msql_Listfields() retrieves information about the given tablename. Its arguments are the database name and the table name. A result pointer is returned, which can be used with msql_FieldFlags($result,$i), mysql_FieldLen($result,$i), msql_FieldName($result,$i), msql_FieldType($result,$i). A result identifier is a positive integer.
The function returns -1 if a error occurs. A string describing the error is placed in $phperrmsg, and unless the function was called as @msql(), in which case this error string is also printed. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
$result = msql_ListTables($database)
msql_ListTables() takes a database name and result pointer, much like the msql() function. Use the msql_TableName($result,$i) function to extract the actual table names from the result pointer. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_NumFields($result)
msql_NumFields() returns the number of fields in a result. The argument is the result identifier returned by the $result = msql($database,$query) function. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_NumRows($result)
msql_NumRows() simply returns the number of rows in a result. The argument is the result identifier returned by the $result = msql($database,$query) function. This function is only available if mSQL support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_RegCase(string)
msql_RegCase() converts a string argument to the regular expression needed to send to mSQL in order to obtain a case-insensitive match. For example, this turns the string "abc" into "[Aa][Bb][Cc]". This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_Result($result,$i,field)
msql_Result() displays a field from a returned record. Its arguments are
- the result identifier returned by the msql() function
- an integer which is the index of the record to be viewed
- a field name
<?
$name = "bob";
$result = msql($database,"select * from table where firstname='$name'");
$num = msql_numrows($result);
echo "$num records found!<p>";
$i=0;
while($i<$num);
echo msql_result($result,$i,"fullname");
echo "<br>";
echo msql_result($result,$i,"address");
echo "<br>";
$i++;
endwhile;
>
- connects to the mSQL engine on the local machine
- sets the name variable to "bob"
- sends a query which asks for all the fields from a table where the firstname field is set to "bob"
- displays the number of records it found
- loops through each of the found records
- displays the fullname and address fields for each record
As you can see, it would be trivial to add HTML markup tags around the printed fields to format the results in whatever manner you prefer. Note that there is no msql_connect() call. msql_connect() need only be called if you need a connection to a remote database. This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
msql_TableName($result,$i)
msql_TableName() takes a result pointer returned by the $result = msql_ListTables($database) function as well as an integer index and returns the name of a table. The msql_NumRows($result) function can be used to determine the number of tables in the result pointer. For example:
<?
$result = msql_listtables("dbname");
$i=0;
while($i < msql_numrows($result));
$tb_names[$i]=msql_tablename($result, $i);
echo $tb_names[$i];
echo "<BR>";
$i++;
endwhile;
>
This function is only available if mSQL support is enabled in PHP as described in "PHP Configuration" on page 11-2.
$result = mysql($database,$query)
mysql() sends a mysql query. Its arguments are the database name and the query string, for example,
<?mysql("MyDatabase" , "select * from table")>
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_affected_rows()
This returns number of rows affected by the last INSERT, UPDATE or DELETE query.
mysql_close()
mysql_close() closes the socket connection to the mysql daemon, if an open connection exists.
mysql_connect($hostname)
<?mysql_connect("localhost")>
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_CreateDB($database)
mysql_CreateDB() creates the given database.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_dbName($result,$i)
mysql_dbName() returns the database name stored in position $i of the result pointer returned from the $result = mysql_ListDBs() function. The mysql_NumRows($result) function can be used to determine how many database names are available.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_DropDB($database)
mysql_DropDB() deletes the given mysql database. This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
NOTE: Use this with caution, as all data in the database will be lost.
mysql_FieldFlags($result,$i)
- "not null"
- "primary key"
- a combination of the two
- an empty string
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_FieldLen($result,$i)
mysql_FieldLen() returns the length of the specified field.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_FieldName($result,$i)
mysql_FieldName($result,2);
returns the name of the second field in the result associated with the result identifier.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_FieldType($result,$i)
- "int"
- "char"
- "real"
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_FreeResult($result)
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_insert_id()
$result = mysql_ListDBs()
mysql_ListDBs() returns a result pointer containing the databases available from the current mysql daemon. Use the mysql_dbName($result,$i) function to traverse this result pointer.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
$result = mysql_Listfields($database,$table)
mysql_listfields() retrieves information about the the given table. Its arguments are the database name and the table name. A result pointer is returned that can be used with mysql_FieldFlags($result,$i), mysql_FieldLen($result,$i), mysql_FieldName($result,$i), mysql_FieldType($result,$i). A result identifier is a positive integer.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
$result = mysql_ListTables($database)
mysql_ListTables() takes a database name and result pointer, much like the $result = mysql($database,$query) function. Use the mysql_TableName($result,$i) function to extract the actual table names from the result pointer.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_NumFields($result)
mysql_NumFields() returns the number of fields in a result. Its argument is the result identifier returned by the $result = mysql($database,$query) function.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_NumRows($result)
mysql_NumRows() simply returns the number of rows in a result. The argument is the result identifier returned by the $result = mysql($database,$query) function.
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_Result($result,$i,field)
mysql_Result() displays a field from a returned record. Its arguments are the result identifier returned by the $result = mysql($database,$query) function, an integer which is the index of the record to be viewed, and a field name. The field argument supports the "table.field" syntax for handling results from a join.
<?
$name = "bob";
$result = mysql($database,"select * from table where firstname='$name'");
$num = mysql_numrows($result);
echo "$num records found!<p>";
$i=0;
while($i<$num);
echo mysql_result($result,$i,"lcase(fullname)");
echo "<br>";
echo mysql_result($result,$i,"address");
echo "<br>";
$i++;
endwhile;
>
- connects to the mysql engine on the local machine
- sets the name variable to "bob"
- sends a query which asks for all the fields from a table where the firstname field is set to "bob"
- displays the number of records it found
- loops through each of the found records
- displays the fullname and address fields for each record
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
mysql_TableName($result,$i)
mysql_TableName() takes a result pointer returned by the $result = mysql_ListTables($database) function as well as an integer index, and returns the name of a table. Use the mysql_NumRows($result) function to determine the number of tables in the result pointer. For example:
<?
$result = mysql_listtables("dbname");
$i=0;
while($i < mysql_numrows($result));
$tb_names[$i]=mysql_tablename($result, $i);
echo $tb_names[$i];
echo "<BR>";
$i++;
endwhile;
>
This function is only available if mysql support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Next(variable)
<?
Reset($array);
$i=0;
while($i < count($array));
echo key($array);
next($array);
$i++;
endwhile;
>
OctDec(octal_number)
OctDec() converts an octal number to a decimal number. See also DecOct(number).
openDir(directory)
openDir() opens the specified directory and places an internal pointer to the beginning of the directory. Directory entries are read using the readDir() function, and an opened directory should be closed with the closeDir() function.
Ord(arg)
Ord() returns the ASCII value of the first character of arg.
Ora_Close(conn_ind)
Ora_Commit(conn_ind)
Ora_CommitOff(conn_ind)
Ora_CommitOn(conn_ind)
Ora_Exec(cursor_ind)
Ora_Fetch(cursor_ind)
Ora_GetColumn(cursor_ind, column)
Ora_GetColumn() fetches data for a single column in a returned row. Ora_Fetch(cursor_ind) must have been called prior to Ora_GetColumn().
Ora_Logoff(conn_ind)
Ora_Logoff() disconnects the logon data area belonging to conn_ind and frees used Oracle resources.
Ora_Logon(userID, password)
Ora_Open(conn_ind)
Ora_Parse(cursor_ind, sql_statement[, defer])
Ora_Rollback(cursor_ind)
Ora_Rollback() rolls back the current transaction. See Ora_Commit(conn_ind) for a definition of the current transaction.
PassThru(command_string [,return_var])
pclose(fp)
Pclose() closes a pipe opened using the fp = popen(command,mode) function.
pg_Close(connection_id)
pg_Close() closes the connection to a Postgres95 database associated with the given connection identifier. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
$connection = pg_Connect(host, port, options, tty, dbname)
This function returns a connection_id. This identifier is required by other Postgres95 functions. You can have multiple connections open at once. This function returns a 0 on error. It is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_DBname(connection_id)
pg_DBname() returns the name of the database that the given Postgres95 connection identifier is connected to. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_ErrorMessage(connection_id)
If an error occurred on the last database action for which a valid connection exists, this function returns a string containing the error message generated by the back-end server. This function is only available if Postgres95 support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
$result = pg_Exec(connection_id, query_string)
pg_Exec() sends an SQL statement to the Postgres95 database specified by the connection_id. The connection_id must be a valid identifier returned by $connection = pg_Connect(host, port, options, tty, dbname). The return value of this function is an identifier to be used to access the results from other Postgres95 functions.
This function returns 0 on error. It returns 1 when the commands execute correctly but are not expected to returned data (insert or update commands, for example). Note that commands which return no data still return a valid result greater than 1. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_FieldName(result_id, field_number)
pg_FieldName() returns the name of the field occupying the given field_number in the given Postgres95 result identifier. Field numbering starts from 0. This function is only available if Postgres95 support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_FieldPrtLen(result_id, row_number, field_name)
pg_FieldPrtLen() returns the actual printed length (number of characters) of a specific value in a Postgres95 result. Row numbering starts at 0. This function returns -1 on an error. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_FieldNum(result_id, field_name)
pg_FieldNum() returns the number of the column slot that corresponds to the named field in the given Postgres95 result identifier. Field numbering starts at 0. This function returns -1 on error. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_FieldSize(result_id, field_name)
pg_FieldSize() returns the internal storage size (in bytes) of the named field in the given Postgres95 result. A field size of 0 indicates a variable-length field. This function returns -1 on error. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_FieldType(result_id, field_number)
pg_FieldType() returns a string containing the type name of the given field in the given Postgres95 result identifier. Field numbering starts at 0. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_FreeResult(result_id)
You only need pg_FreeResult() if you are worried about using too much memory while your script is running. All result memory is automatically freed when the script is finished. However, if you are sure you are not going to need the result data again in a script, you may call pg_FreeResult() with the result identifier as an argument, and the associated result memory is freed. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_GetLastOid()
pg_GetLastOid() can be used to retrieve the Oid assigned to an inserted tuple if the last command sent via pg_Exec() was an SQL Insert. This function returns a positive integer if there was a valid Oid. It returns -1 if an error occurred or the last command sent via pg_Exec() was not an Insert. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_Host(connection_id)
pg_Host() returns the host name the given Postgres95 connection identifier is connected to. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_NumFields(result_id)
pg_NumFields() returns the number of fields (columns) in a Postgres95 result. The argument is a valid result identifier returned by $result = pg_Exec(connection_id, query_string). This function returns -1 on error. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_NumRows(result_id)
pg_NumRows() returns the number of rows in a Postgres95 result. The argument is a valid result identifier returned by $result = pg_Exec(connection_id, query_string). This function returns -1 on error. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_Options(connection_id)
pg_Options() returns a string containing the options specified on the given Postgres95 connection identifier. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_Port(connection_id)
pg_Port() returns the port number that the given Postgres95 connection identifier is connected to. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_Result(result_id, row_number, field_name/index)
This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
pg_tty(connection_id)
pg_tty() returns the TTY name that server-side debugging output is sent to on the given Postgres95 connection identifier. This function is only available if Postgres95 support is enabled in PHP as described in "PHP Configuration" on page 11-2.
phpInfo()
phpVersion()
phpVersion() returns the version number of PHP/FI currently running.
fp = popen(command,mode)
Popen() opens a pipe to a command and returns a file pointer index. This file pointer index can be used by fgets($fd,bytes), fputs(fp,string), and fclose($fd). The function's arguments are the command to run and the mode. The mode can be either "r" for read or "w" for write. See the UNIX C library popen man page for more details. Any file opened with popen() should be closed using the pclose(fp) function.
pos(var)
pow(x,y)
pow() valuates x raised to the power of y. See also Exp(arg).
Prev(variable)
Prev() moves the internal array pointer for the given variable to the previous item in the array. If already at the beginning of the list, the pointer points to the first item. The function returns the value of the new item. It is useful for traversing an associative array in reverse order. See the example in the End(variable) definition. See also Next(variable).
PutEnv(string)
QuoteMeta(arg)
Rand()
Rand() returns a random number between 0 and RANDMAX. Be sure to seed your random number generator by calling Srand(integer) before you call rand(). You only need to do this once. You can determine RANDMAX using the getRandMax() function.
readDir()
$size = ReadFile(filename)
ReadLink(path)
ReadLink() does the same as the readlink C function and returns the contents of the symbolic link path, or -1 in case of error. See also LinkInfo(path).
reg_Match(regex,arg[,regs])
This function has been replaced by the ereg(expr,arg[,regex]) function. It is, however, still available for backward compatibility. reg_Match() returns non-zero if the regex is matched in the arg string. For example, the condition
<?if (reg_match("^This.*", "This is an example string")>
is true, since the "^This.*" expression instructs PHP to match the word "This" at the beginning of the string, then match any characters afterwards. If the regs argument is present, then match registers are filled into positions 0-10 in the array named by regs. Register 0 always contains the full matched string. For more information on regular expressions, see "Regular Expressions" on page 11-9.
reg_replace(expr,replace,arg)
This function has been replaced by the ereg_replace(regex,replace,arg) function. It is, however, still available for backward compatibility. reg_replace() scans the entire argument string and replaces any portions of the string matched by the given expression with the replacement string. For example, in the string, "This is an example string," you can replace every space with a dash with the command:
reg_replace(" ","-","This is an example string")
For more information on regular expressions, see "Regular Expressions" on page 11-9.
reg_Search(regex,arg[,regs])
This function has been replaced by the ereg(expr,arg[,regex]) function. It is, however, still available for backward compatibility. reg_Search() scans the entire argument string for any matches to the given regex. If a match is found, the fucntion returns the portion of the string starting where the match occurred. If no match is found, a zero-length string is returned. If the regs argument is present, then match registers are filled into positions 0-10 in the array named by the regs argument. Register 0 is always assigned the full matched string. For more information on regular expressions, see "Regular Expressions" on page 11-9.
Rename(old,new)
This function renames filename old to new, similar to the UNIX C rename() function.
Reset(variable)
<?
Reset($array);
$i=0;
while($i < count($array));
echo $array[]; /* pointer automatically moves ahead one */
$i++;
endwhile;
>
See also End(variable) and Next(variable).
Return(value)
Return() exits the current function call and returns the specified value to the caller. See "User-Defined Functions" on page 11-13 for more information about user-defined functions.
rewind($fd)
rewind() resets a file pointer identified by the $fd argument, which is the return value of the $fp = fopen(file,mode) call. The file pointer is positioned at the beginning of the file. See also pos = ftell(fp) and fseek(fp,pos).
rewindDir()
rewindDir() moves the current directory pointer back to the beginning of the directory. Use the openDir(directory) function to open a directory before calling this function.
RmDir(dir)
RmDir() removes the given directory. See the Unlink(file) function to remove regular files.
RSort(array)
SetCookie(name,value,expire,path,domain,secure)
SetCookie("TestCookie","Test Value");
SetCookie("TestCookie",$value,time()+3600); /* expire in 1 hour */
SetCookie("TestCookie",$value,time()+3600,"/~rasmus/",".utoronto.ca",1);
echo $TestCookie;
SetErrorReporting(arg)
SetLogging(arg)
SetShowInfo(arg)
SetType(variable,type)
SetType() sets the type of a variable. The type argument is one of the following:
- "integer"
- "double"
- "string"
See also the GetType(variable) function.
shl(n,b)
This shifts the value n left by b bits.
shr(n,b)
This shifts the value n right by b bits.
Sin(arg)
Sin() returns the sine of arg in radians. See also Cos(arg) and Tan(arg).
Sleep(secs)
Solid_Close(connection_id)
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
$connection = Solid_Connect(data source name, username, password)
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
$result = Solid_Exec(connection_id, query_string)
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Solid_FetchRow(result_id)
Solid_FetchRow() fetches a row of the data that was returned by Solid_Exec(). After Solid_FetchRow() is called, the fields of that row can be accessed with Solid_Result(result_id, field name|index). Every time Solid_FetchRow() is called, a new row can be accessed by Solid_Result(). If Solid_FetchRow() succeeds (there is a new row), 1 is returned. If there are no more rows, Solid_FetchRow() returns 0. The return value of Solid_FetchRow() can be used as the condition of a while loop.
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Solid_FieldName(result_id, field_number)
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Solid_FieldNum(result_id, field_name)
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Solid_FreeResult(result_id)
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Solid_NumFields(result_id)
Solid_NumFields() returns the number of fields (columns) in a Solid result. The argument is a valid result identifier returned by $result = Solid_Exec(connection_id, query_string). This function returns -1 on error.
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Solid_NumRows(result_id)
Solid_NumRows() returns the number of rows in a Solid result. The argument is a valid result identifier returned by $result = Solid_Exec(connection_id, query_string). This function returns -1 on error.
NOTE: The Solid SQL server uses ODBC as its primary (and only) interface. SolidNumRows() uses SQLRowCount() at a low level to get the number of rows. SQLRowCount() includes unnecessary limitations, strange exceptions, and other odd behaviors. This means that the function only returns the number of rows affected by an INSERT, an UPDATE, or a DELETE clause. As a workaround, you can try the count() statement of SQL or a while-loop that counts the number of rows.
If you need Solid_NumRows() to figure out how many records to read after a SELECT clause, try checking the return value from Solid_FetchRow(result_id) instead. For example, instead of
$num = Solid_NumRows();
$i=0;
while ($i < $num) {
/* print results... */
$i++;
}
while(Solid_FetchRow($result)) {
/* print results... */
}
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Solid_Result(result_id, field name|index)
Solid_Result() returns values from a result identifier produced by $result = Solid_Exec(connection_id, query_string). The field name specifies which cell in the row to return. Instead of naming the field, you may use the field index as an unquoted number. Field indices start from 0.
This function is only available if Solid support has been enabled in PHP as described in "PHP Configuration" on page 11-2.
Sort(array)
Sort() sorts a PHP array in ascending order. It understands the three variable types and sorts alphabetically if the array contains strings and numerically if the array contains numbers. In the case of an array that contains a mixture of types, the first type in the array specifies the sort method. See also RSort(array).
Soundex(string)
String Soundex Key Euler and Ellery E460 Gauss and Ghosh G200 Hilbert and Heilbronn H416 Knuth and Kant K530 Lloyd and Ladd L300 Lukasiewicz and Lissajous L222
Sprintf(format,arg)
Sqrt(arg)
Sqrt() returns the square root of arg.
Srand(integer)
Srand() seeds the random number generator. This function takes any integer as an argument. One choice for a seed value is to use the Date(format,time) function to get the current number of seconds past the minute. Note that this function does not return a value. It simply seeds the random number generator for subsequent calls to the Rand() function. For example:
<?srand(date("s"))>
strchr(string,arg)
strchr() and strstr(string,arg) are identical functions. They can be used interchangeably, and both are included for completeness. They return the portion of the string argument starting at the point where the given sub-string arg is found. For example, in the string, "This is an example string," the call
<echo strstr($string,"an ")>
returns the string "an example string."
StripSlashes(arg)
StripSlashes() unescapes the string argument. See also AddSlashes(arg).
strlen(string)
strlen() returns the length of the string.
strrchr(string,arg)
strstr(string,arg)
strstr() and strchr(string,arg) are identical functions. They can be used interchangeably, and both are included for completeness sake. They return the portion of the string argument starting at the point where the given sub-string arg is found. For example, in the string, "This is an example string," the call
<echo strstr($string,"an ")>
returns the string: "an example string."
strtok(string,arg)
<?
$string = "This is an example string";
$tok = strtok($string," ");
while($tok);
echo "Word=$tok<br>";
$tok = strtok(" ");
endwhile;
>
strtolower(string)
strtolower() converts the string argument to all-lowercase characters.
strtoupper(string)
strtoupper() converts the string argument to all-uppercase characters.
strtr(input,set1,set2)
strval(variable)
strval() returns the string value of the variable. See also the intval(variable) and doubleval(variable) functions.
substr(string, start, length)
sybSQL_CheckConnect()
This function returns 1 if the connection to the database has been established and 0 otherwise.
sybSQL_Connect()
The environment variables are as follows:
Variable Description DSQUERY The alias of the Sybase server as defined in the Sybase interface file DBUSER Connect to the Sybase server as this user DBPW Password of the user The function returns 1 on success and 0 on failure.
sybSQL_DBuse(database)
This function issues a Sybase Transact-SQL use command for the specified database. For example:
sybsql_dbuse("pubs2");
The function returns 1 on success and 0 on failure.
sybSQL_Fieldname(index)
sybsql_fieldname(0);
sybSQL_GetField(field)
$value=sybsql_getfield("@10");
NOTE: sybSQL_NextRow() must be called before calling this function. sybSQL_NextRow()) must be called if the row pointer needs to be incremented because this function only reads the current row in the row buffer.
sybSQL_IsRow()
This function indicates whether the current SQL command returned any rows.
The function returns 1 if the SQL command returned any rows, and 0 if the command did not.
sybSQL_NextRow()
This function increments the row pointer to the next result row.
sybSQL_NumFields()
This function returns the number of fields in a current result row.
sybSQL_NumRows()
sybSQL_Query()
$rc=sybsql_query("select * from authors");
The function returns 1 if the query is passed successfully, and 0 if the request fails.
sybSQL_Result(string)
<?
/*
** assuming all the necessary variables for
** connection is already set. please note, NO error checking is
** done. You should always check return code of a function.
*/
/* connect */
$rc=sybsql_connect();
/* use the pub2 database */
$rc=sybsql_dbuse("pubs2");
/* send the SQL request */
$rc=sybsql_query("select * from authors");
$i=0;
/* find the no of rows returned */
$nrows=sybsql_numrows();
/* start table */
echo "<table border>\n";
/*
** print only first and 2nd field
*/
while($i<$nrows) {
sybsql_result("<tr><td>@0</td>@1</td></tr>\n");
$i++;
}
/* end table */
echo "</table>\n";
>
The above example uses an HTML table to format the output. Any other HTML tags are also valid.
sybSQL_Result_All()
NOTE: This function should not be called inside a loop.
sybSQL_Seek(row)
$rc=sybsql_seek(10);
Symlink(target,link)
Symlink() creates a symbolic link. See the Link(target,link) function to create hard links.
System(command_string [,return_var])
System() is just like the C system() command in that it executes the given UNIX command and outputs the result. If a variable is provided as the second argument, then the return status code of the executed UNIX command is written to this variable. If you are going to allow data coming from user input to be passed to this System() function, then you should use the EscapeShellCmd(string) function to make sure that users cannot trick the system into executing commands. If you need to execute a command and have all the data from the command passed directly back without any interference, use the PassThru(command_string [,return_var]) function. See also the Exec(command_string [, array [,return_var]]) function.
Tan(arg)
Tan() returns the tangent of arg in radians. See also Sin(arg) and Cos(arg).
TempNam(path, prefix)
Time()
Time() simply returns the current local time in seconds since the UNIX epoch (00:00:00 Jan. 1 1970). It is equivalent to calling Date("U"). If you need better than per-second granularity, use the Microtime() function.
Umask(mask)
Unlink(file)
Unlink() deletes the given file, similar to the UNIX C unlink() function. See the RmDir(dir) function for removing directories.
UnSet($var)
UrlDecode(string)
UrlEncode(string)
USleep(microsecs)
USleep() delays for the given number of microseconds, similar to the UNIX C usleep() function. See also the Sleep(secs) function.
Virtual(filename)
[Top] [Prev] [Next] [Last]
© 1998 C2Net International
Feedback: stronghold-docs@c2.net![]()