View Full Version : mysql error on localhost

02-10-2007, 11: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

this is in my createdb.php

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

if (!$result)
echo "error";
echo "success";

02-10-2007, 12:04 PM
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.

$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


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