...

View Full Version : mysql error on localhost



rafiki
02-10-2007, 10:31 AM
hi im tryin to run a tst database but get errors

Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\Program Files\xampp\xampp\htdocs\createdb.php on line 3

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\Program Files\xampp\xampp\htdocs\createdb.php on line 3
errorsuccess

this is in my createdb.php

<?php
$query = "CREATE DATABASE phpcake";
$result = mysql_query($query);

if (!$result)
{
echo "error";
}
{
echo "success";
}
?>

mic2100
02-10-2007, 11:04 AM
This is how you create a new database. the query that you are trying to do can only be done once a connection as been made to a specific database.



<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}

$sql = 'CREATE DATABASE my_db';
if (mysql_query($sql, $link)) {
echo "Database my_db created successfully\n";
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
}
?>


you should go and read up on this stuff at

http://uk.php.net/manual/en/ref.mysql.php

rafiki
02-10-2007, 11:12 AM
thats it thanks :) i havent done anythng in php for sometime



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum