PHP vs MYSQL

Problems with the Windows version of XAMPP, questions, comments, and anything related.

PHP vs MYSQL

Postby rockin_woody » 13. April 2005 17:44

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
rockin_woody
 
Posts: 2
Joined: 13. April 2005 16:46

Postby Wiedmann » 13. April 2005 18:48

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".
Wiedmann
AF Moderator
 
Posts: 17106
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 36 guests