Forums

PHP

This topic is locked

Creating a MySQL database through PHP

Posted 04 Oct 2002 19:14:53
1
has voted
04 Oct 2002 19:14:53 Dom Fee posted:
Hi Guys I am having some difficulty creating a MYSql database through PHP.
Here is what i have:

<?php
$link = @mysql_connect("localhost";

if ($link == false) {
echo "Failed to connect to MySQL server!";
exit;
}

if (mysql_create_db("sampledb" == false) {
echo("Error creating database sampledb!";
exit;
}

echo("Database sampledb created!";

mysql_close($link);
?>

I have no idea why it wont create it

BTW - local host,MySQL and PHP all operating successfully

Cheers
Dom
www.2deep.uk.com

Replies

Replied 04 Oct 2002 23:42:51
04 Oct 2002 23:42:51 Keith Slater replied:
are you getting any errors at all? Does anything echo?

Try taking out the @ just to make sure your not missing any errors.

Keith Slater
Replied 04 Oct 2002 23:52:07
04 Oct 2002 23:52:07 Keith Slater replied:
Actually your problem is because its not running mysql as a user, or a right user...

try this
<pre id=code><font face=courier size=2 id=code>mysql_connect("localhost", "root"; </font id=code></pre id=code>

although you probably dont want to run mysql as root unless this is like an internal or testing thing.

Keith Slater

Reply to this topic