For Each Array Item

December 14, 2007

#!/usr/bin/php
<?
$theArray = array(‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’);
foreach ($theArray as $theItem) {
echo “$theItem\n”;
}
?>


MySQL Password

December 13, 2007

mysql> set password for root@localhost = password(‘phpxphp’);

Query OK, 0 rows affected (0.08 sec)

mysql> \q

Bye

shell> mysql -u root -p
Enter password: phpxphp

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 53
Server version: 5.0.45 MySQL Community Server (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql>


MySQL Help

December 11, 2007

shell> mysql –help > ~/desktop/mysqlhelp.txt

shell> sudo mysql

Welcome to the MySQL monitor.
Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.45
MySQL Community Server (GPL) 

Type 'help;' or '\h' for help.
Type '\c' to clear the buffer.

mysql> help

List of all MySQL commands:
Note that all text commands must be first on line and end with ';' 

?         (\?) Synonym for `help'.
clear     (\c) Clear command.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
               NOTE: Takes the rest of the line as new delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset.
               Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
For server side help, type 'help contents'

mysql> help contents

You asked for help about help category: "Contents"
For more information, type 'help <item>',
where <item> is one of the following categories:    

Account Management
Administration
Data Definition
Data Manipulation
Data Types
Functions
Functions and Modifiers for Use with GROUP BY
Geographic Features
Language Structure
Storage Engines
Stored Routines
Table Maintenance
Transactions
Triggers

mysql> help account management

You asked for help about help category: "Account Management"
For more information, type 'help <item>',
where <item> is one of the following topics:

CREATE USER
DROP USER
GRANT
RENAME USER
REVOKE
SET PASSWORD

mysql> help create user

Name: 'CREATE USER'
Description:
Syntax:
CREATE USER user [IDENTIFIED BY [PASSWORD] 'password']
         [, user [IDENTIFIED BY [PASSWORD] 'password']] ...

URL: http://dev.mysql.com/doc/refman/5.0/en/create-user.html

mysql>


MySQL Test

December 7, 2007

shell> sudo mysqladmin version

mysqladmin  Ver 8.41 Distrib 5.0.45, for apple-darwin8.6.0 on powerpc
Copyright (C) 2000-2006 MySQL AB
Server version  5.0.45
Protocol version  10
Connection  Localhost via UNIX socket
UNIX socket /tmp/mysql.sock
Uptime: 28 sec
Threads:
1  Questions:
1  Slow queries:
0  Opens:
12 Flush tables:
1  Open tables:
6  Queries per second
   avg: 0.036

shell> mysqlshow

+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+

shell> mysql -u root test

 Welcome to the MySQL monitor.
 Commands end with ; or \g.
 Your MySQL connection id is 8
 Server version: 5.0.45
 MySQL Community Server (GPL)
 Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> \q

 Bye

MySQL Installation

December 4, 2007

mysql-5.0.45-osx1010.4-powerpc.pkg will install itself into /usr/local/, create a symbolic link /usr/local/mysql, and creates the grant tables in /usr/local/data/ by executing mysql_install_db.

Change user and group ownership attributes to mysql:

shell> cd /usr/local/mysql
shell> ls -l
shell> sudo chown -R mysql .
shell> sudo chgrp -R mysql .
shell> ls -l

The “bin” directory contains client programs and the server.

Append the full pathname of this directory to the “PATH” environment variable in the .profile file in the home directory so that the shell finds the MySQL programs properly:

shell> cat >> ~/.profile # APPEND!
export PATH=$PATH:/usr/local/mysql/bin
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
^D%
shell> cat ~/.profile

The above sequence also adds shortcuts for mysql and mysqladmin commands, which may be redundant.

Start MySQL:
System Preferences… > Other > MySQL > Start MySQL Server

Test MySQL:

shell> cd /usr/local/mysql/mysql-test
shell> sudo ./mysql-test-run.pl

 ERROR: Failed to start master mysqld 0


Configuration File (php.ini)

November 30, 2007

Just ignore this post for right now.

<? echo phpinfo() ?>

mentions that it’s looking for a file in /etc/
named php.ini

The following changes will remove the exception
to allowing notices to be reported.*

Use BBEdit to Open Hidden php.ini.default
and save it to Desktop as php.ini

Change the line:

error_reporting = E_ALL

Then, in the terminal:

sudo mv desktop/php.ini /etc/php.ini

*It also changes a lot of other things, too, so dont make these changes just yet. Also, Note that MySQL and ODBC support is now built in.

BTW, you can execute this file, which contains the above echo line, in Terminal:

php /library/webserver/documents/phpinfo.php


Apache Configuration

November 29, 2007

Uncomment a few lines in the httpd.conf file
located in the .private/etc/httpd/ folder:

LoadModule php4_module libexec/httpd/libphp4.so
AddModule mod_php4.c

Check to see that these lines are automatically turned on:

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.html index.php

ScriptAlias might need some attention as well.

Stop, then Start Apache:

System Preferences… > Sharing > Personal Web Sharing


History

November 29, 2007

Ramus Lerdorf conceived the idea of PHP in the fall of 1994.

Until then, Perl was the scripting language of choice for doing web forms and other server side programming. However, PHP is designed specifically for the web, and it’s easier to integrate into HTML.


hello.php

November 29, 2007

Execute PHP code in BBEdit on Mac OS X:

#!/usr/bin/php
<?echo “Hello World”;?>

In practice, however, PHP code is usually embedded in html. Save this code in a file named hello.php in local host:

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<SCRIPT LANGUAGE=”php”>
echo “USE PHP AS A MULTI LINE “;
echo “SCRIPT LANGUAGE”;
</SCRIPT><br>
<?echo “or use simple percent\rsigns<BR>”;?>
two plus two is <?= 2 + 2 ?>
</body>
</html>

and this link will execute it:

http://localhost/hello.php

producing a page with this source:

<html>
<head>
<title>PHP Test</title>
</head>
<body>
USE PHP AS A MULTI LINE SCRIPT LANGUAGE<br>
or use simple percent
signs<BR>two plus two is 4</body>
</html>

which appears in the browser as:

USE PHP AS A MULTI LINE SCRIPT LANGUAGE
or use simple percent signs
two plus two is 4


									

Hello PHP World!

November 29, 2007

PHP is an open source, server-side web-scripting language for creating dynamic web pages. Use it for interactive web and database-driven state-of-the-art websites that are:

  • Modular
  • Multi-tiered
  • Scalable
  • Efficient
  • Secure

Apache, MySQL, and PHP together make a nice combination.
Some familiar PHP sites:


Follow

Get every new post delivered to your Inbox.