Database name

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

Database name

Postby Miepz » 30. March 2005 10:59

Hi,

I'm totally new to php, and I've installed apache friends. Everything works fine, except the following:

connect.php:

$server = "localhost";
$gebruiker = "root";
$wachtwoord = "";
$db = "test";

$connectie = mysql_connect($server,$gebruiker,$wachtwoord)
or die ("Kon niet connecteren met de server");
mysql_select_db($db,$connectie)
or die ("Kon de database niet selecteren");


firstconnect.php:

<html>
<head>
<title>my first php connection </title>
</head>
<body>
<?php
include "connect.php";
$query = "SELECT * FROM `producten` WHERE `prijs` > '2' ";
$sql = mysql_query($query)or die ( mysql_error( ) );
while($record = mysql_fetch_object($sql)){
echo"".$record->naam."<br>";
}
?>
</body>
</html>


The error I get:
...No database selected

I use the default "test" database on the mysql server. I've put a table "producten" in it.

I hope my explanation is clear.

Thanks.
Miepz
 
Posts: 3
Joined: 29. March 2005 21:27

Postby Dave_L » 30. March 2005 20:57

Try replacing:

Code: Select all
include "connect.php";


with

Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', '1');
require "connect.php";
User avatar
Dave_L
 
Posts: 212
Joined: 23. October 2004 00:43

Postby keepsedge » 31. March 2005 17:18

all that will do is send a bunch of errors that he's getting. by default you wouldn't need that code as the XAMPP php.ini already displays all errors anyway.

try using this script

Code: Select all
<?php

// errors
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

// conecting to your database

if ($dbc = mysql_conect ('localhost', 'root', 'root_password')) {
   echo (" Conected to mysql server");
     
     if (!@mysql_select_db ('test')) {
       die ("<p>could not select the dabase \"test\" because of<br /><b>" . mysql_error() . "</b></p>");
        }


} else {
   echo ("error conecting to mysql because of <br /><b>" . mysql_error() . "</b>");

// close conection
mysql_close ();
?>

replace root_password in the if statement with whatever you're root password is. If you'd like to use a different user other then root, then change root to whatever the name is and rott_password to that user's password.

This is a simple script that makes sure you can coect to your mysql server. Then will connect to your database. if there is a problems it will print the mysql errors recived.

if there is an error, copy and paste it into here and i'll have a look at it.

for some reason the include() function doesn't always work.. use require() or require_once ().

</keeper>
keepsedge
 
Posts: 33
Joined: 24. December 2004 11:04

Postby Miepz » 04. April 2005 13:45

Hello keepsedge,

I've done everything you've said, and this is the error I get:

error:
// errors ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); // conecting to your database if ($dbc = mysql_conect ('localhost', 'root', '')) { echo (" Conected to mysql server"); if (!@mysql_select_db ('test')) { die ("
could not select the dabase \"test\" because of
" . mysql_error() . "

"); } } else { echo ("error conecting to mysql because of
" . mysql_error() . ""); No database selected
Miepz
 
Posts: 3
Joined: 29. March 2005 21:27

Postby Miepz » 04. April 2005 14:03

Ok, i've noticed the following:

if I put everything in one file (so without the include/require function), everything works!
So I can go on now, but still, it is a pity that I can't put my connection in a different file, so I can include it everywhere I want.
If somebody knows what I'm doing wrong,...

And thanks keepsedge for your help!!
Miepz
 
Posts: 3
Joined: 29. March 2005 21:27

Postby thekingofcaseys » 06. April 2005 00:24

Didyou set the main root PHPMYADMIN password from within xampp itself, I got this error because i never did mine after you have made the xampp directory safe click on the PHPMYADMIN link and enter a new password within side PHPMYADMIN
thekingofcaseys
 
Posts: 50
Joined: 27. December 2004 15:38


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 143 guests

cron