totally new to databases! help me plz

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kakmonstret
Forum Newbie
Posts: 1
Joined: Sun Mar 23, 2003 5:50 am
Location: Stockholm, Sweden
Contact:

totally new to databases! help me plz

Post by kakmonstret »

hello i have had some lessons in school in php so i know few things, but this with databases i dont utnderstand.

i have installed php on IIS on my win2000 computer.
then i installed MySQL and then phpmyadmin.

i have an example i made in school on linux machines (it works there), tested it here nothing of that works so i have no idea how to make things work on this machine too?

this is the code from my first file.

<?php
$host = "localhost";
$user = "root";
$password = "";
$DBName ="mindatabas";

$link = mysql_connect ($host, $user, $password);

if (mysql_create_db ($DBName, $link))
{
print ("din databas $DBname skapades");
}
else
{
print ("din databas $DBname skapades INTE!!");
}

mysql_close ($link);

?>

my browser complaigns about this:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in C:\projekt\public_html\db\cr8db.php on line 7

Notice: mysql_create_db() [function.mysql-create-db]: This function is deprecated, please use mysql_query() to issue a SQL CREATE DATABASE statement instead. in C:\projekt\public_html\db\cr8db.php on line 9

Warning: mysql_create_db(): supplied argument is not a valid MySQL-Link resource in C:\projekt\public_html\db\cr8db.php on line 9

Notice: Undefined variable: DBname in C:\projekt\public_html\db\cr8db.php on line 15
din databas skapades INTE!!
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\projekt\public_html\db\cr8db.php on line 18


heheeh what to do? :)
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Almost all the errors are related to the fact that the script cannot connect to the database - are you sure that MySQL is running? Can you access your databases using phpMyAdmin?

This error:
Notice: mysql_create_db() [function.mysql-create-db]: This function is deprecated, please use mysql_query() to issue a SQL CREATE DATABASE statement instead. in C:\projekt\public_html\db\cr8db.php on line 9
is being caused because you are using a function (mysql_create_db()) which (as it tells you) is deprecated and you should be using another function (mysql_query()) instead, so:

Code: Select all

if (@mysql_query("CREATE DATABASE $DBName", $link)) { 
    print "din databas $DBname skapades";
} else { 
    print "din databas $DBname skapades INTE!!";
}
should be used instead of:

Code: Select all

if (mysql_create_db ($DBName, $link)) 
{ 
print ("din databas $DBname skapades"); 
} 
else 
{ 
print ("din databas $DBname skapades INTE!!"); 
}
But of course you need to be able to connect to the database before this'll make a difference.

Mac
Skorp
Forum Newbie
Posts: 3
Joined: Sat Mar 22, 2003 12:17 pm

Post by Skorp »

In Windows 2000, I don't think MySQL starts automatically as a background process. Obviously MySQL starts as a demon on your linux box at school.

For Windows, if you're just goofing around with MySQL, I'd suggest just starting MySQL manually whenever you need it, rather than burdening your machine with yet more background stuff.

Look in the bin directory of your mysql directory - there should be mysqld-shareware.exe somewhere in there. Click on it. Then run your php script.

Tony
Post Reply