[prev in list] [next in list] [prev in thread] [next in thread] 

List:       suse-linux-uk-schools
Subject:    Re: [suse-linux-uk-schools] SQL and PHP
From:       Michael Brown <mbrown () fensystems ! co ! uk>
Date:       2001-02-21 19:21:18
[Download RAW message or body]

On 21 Feb 2001 marknew@dnew.force9.co.uk wrote:
> I have been looking at the possibility of using
> SQL and PHP on the network. However, I only
> know the following things about SQL:
> - It does something with databases
> - It looks difficult to learn.
> I would like to know about your experiences of
> SQL, especially the following:
> Which version is best - PostGreSQL, MySQL?

Horses for courses.  In general: MySQL is fast and simple, PostgreSQL is
not quite as quick but a lot more feature-rich.  Personally I would (and
do) use PostgreSQL because you're unlikely to load the system to a point
where the speed difference becomes an issue (unless you're doing something
really heavy-duty).

PostgreSQL lets you do things like transaction processing and using
triggers.  While you're not likely to need these when you start playing
with it, it's nice to know that you're not going to need to switch
databases if you ever do want to build something sophisticated.

> How easy is it to use with PHP?

Incredibly easy.  As an example, using PostgreSQL:

$db_conn = pg_connect ("host=dbserver port=5432 dbname=mydb user=mydbuser");
$result = pg_exec ($db_conn, "SELECT * FROM mytable");
for ( $row = 0 ; $row < pg_numrows($result) ; $row++ )
{
  $data = pg_fetch_object ($subj_result, $row);
  echo "<li>"
  echo $data->myfield;
  echo "<\li>"
} 

This will connect to a database "mydb" running on a PostgreSQL server on
"dbserver", using the user name "mydbuser".  It will then execute a query
to select all rows from a table "mytable", then will print out the
contents of the field "myfield" for each row as part of an HTML list.

You don't even need to bother freeing resources - PHP does it for you at
the end of the script.

The mod_php manual is very good - it got me up and running in minutes!

> Are there any alternatives that can be used in a
> similar way with PHP?

Lots of databases can be used with PHP.  Which database do you have at the
moment?

HTH,

Michael Brown
http://www.fensystems.co.uk/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic