Simon,

You might want to check that you have the package php5-mysql installed
(PHP extensions that add MySQL functionality).

If not, do a 'sudo apt-get install php5-mysql'

HTH.

Kind regards,
Bernard

2009/8/14 Simon Mutama <[email protected]>:
> All,
>
> I am running a LAMP server on Ubuntu 8.10. Can connect to the database using
> either phpmyadmin or the CLI and manipulate databases successfully. I can
> also run .php files in my browser successfully provided the files do not
> contain any database functions.
>
> However, when I try to use PHP with MySQL functions, I get either a blank
> page or a syntax error. What am I doing wrong?
>
> For instance, the following code results in the syntax error:
>
> Parse error: syntax error, unexpected T_STRING in
> /var/www/Test_Database_Access.php on line 6
>
> <html>
> <head></head>
> <body>
> <?php
> // open connection to MySQL server
> $connection = mysql_connect('localhost', 'guest', 'pass') ↵
> or die ('Unable to connect!');
>
> // select database for use
> mysql_select_db('northwind') or die ('Unable to select database!');
> // create and execute query
> $query = 'SELECT * FROM items';
> $result = mysql_query($query) ↵
> or die ('Error in query: $query. ' . mysql_error());
> // check if records were returned
> if (mysql_num_rows($result) > 0)
> {
> // print HTML table
> echo '<table width=100% cellpadding=10 cellspacing=0 border=1>';
> echo
> '<tr><td><b>ID</b></td><td><b>Name</b></td><td><b>Price</b></td></tr>';
> // iterate over record set
> // print each field
> while($row = mysql_fetch_row($result))
> {
> echo '<tr>';
> echo '<td>' . $row[0] . '</td>';
> echo '<td>' . $row[1] . '</td>';
> echo '<td>' . $row[2] . '</td>';
> echo '</tr>';
> }
> echo '</table>';
> }
> else
> {
> // print error message
> echo 'No rows found!';
> }
> // once processing is complete
> // free result set
> mysql_free_result($result);
> // close connection to MySQL server
> mysql_close($connection);
> ?>
> </body>
> </html>
>
> Thanks
>
> Simon Mutama
>
>
> _______________________________________________
> LUG mailing list
> [email protected]
> http://kym.net/mailman/listinfo/lug
> %LUG is generously hosted by INFOCOM http://www.infocom.co.ug/
>
> The above comments and data are owned by whoever posted them (including
> attachments if any). The List's Host is not responsible for them in any way.
> ---------------------------------------
>
>
>



-- 
Bernard Wanyama
Technical Manager
Syntech Associates Ltd
Suite 422, GPO Building
Plot 35, Kampala Rd, Kampala, UGANDA
Web: www.syntechug.com
Cell: +256 71 2193979
Fixed: +256 41 4251591
_______________________________________________
LUG mailing list
[email protected]
http://kym.net/mailman/listinfo/lug
%LUG is generously hosted by INFOCOM http://www.infocom.co.ug/

The above comments and data are owned by whoever posted them (including 
attachments if any). The List's Host is not responsible for them in any way.
---------------------------------------

Reply via email to