Page 1 of 1

PHP vs MYSQL

PostPosted: 13. April 2005 17:44
by rockin_woody
OK. I am relatively new to all of this stuff. I have managed to intall the apache bundle and I am now able to create html documents which uses php on my machine, by storing the documents in the 'htdocs' folder.

However, I am having some trouble getting mysql to work with php.

I shall explain:

I have created a table using mysql and I now want to connect to the database throught the use of php to return the results of a query. However, this does not work for me.

The HTML document is as follows:


<HTML>
<HEAD>
<TITLE>Connecting to an SQL server</TITLE>
</HEAD>
<BODY>

<?php

require_once('DB.php');
$db = DB::connect("mysql://localhost/test");
if (DB::iserror($db)) { die(db->getMessage()); }

$sql = "SELECT name, phone FROM contacts";
$result = $db -> query($sql);
if (DB::iserror($db)) { die($db->getMessage()); }

while ($result -> fetchInto($row)){
echo $row[ 0 ], $row[ 1 ];
}

?>
</body>
</html>


When i open the HTML i get

getMessage()); } $sql = "SELECT name, phone FROM contacts"; $result = $db -> query($sql); if (DB::iserror($db)) { die($db->getMessage()); } while ($result -> fetchInto($row)){ echo $row[ 0 ], $row[ 1 ]; } ?>

in the browser as if the code is wrong, but i am assured by reliable resources that the code is correct.

I think it may have something to do with where the html fileis kept and where the database is kept, as the readme was a little vague when it came to this.

Can anyone help

...and yes, both the apache and mysql batch files are open whilst i am doing this. I have even tried keeping the mysql window open as a third window while trying to run it.

Cheers

Andy

PostPosted: 13. April 2005 18:48
by Wiedmann
The HTML document is as follows:

The extension of this file must be ".php" und you must open it via the webserver "http://localhost/test.php".