Page 1 of 1

Creating a table

Posted: Sun Apr 22, 2007 3:22 pm
by toasty2
This for some reason doesn't work. I'm pretty sure I understand my PHP book. Is this not right? It doesn't create the table.

Code: Select all

<?php
include 'inc.php'; // This is the file that I have the DB username, password, etc in
mysql_connect($db['host'], $db['user'], $db['pass']);
mysql_select_db($db['db']);

$query = "CREATE TABLE members (
	email VARCHAR(128) NOT NULL PRIMARY_KEY,
	password VARCHAR(64) NOT NULL,
	regdate VARCHAR(12) NOT NULL,
	lastlogin VARCHAR(12),
	country VARCHAR(3) NOT NULL,
	lastip VARCHAR(50),
	PRIMARY KEY(email) )";

mysql_query($query);
mysql_close();
?>

Posted: Sun Apr 22, 2007 3:55 pm
by timvw
Have you checked what mysql_error reports after the call to mysql_query?

Posted: Sun Apr 22, 2007 5:07 pm
by toasty2
Does it output the error to the user? because it doesn't show me any. (I do have errors on)

Posted: Sun Apr 22, 2007 5:22 pm
by Oren
No, it doesn't. You need to print it.

Posted: Mon Apr 23, 2007 12:16 am
by Theory?
Shouldn't it be:

Code: Select all

$connection = mysql_connect($db['host'], $db['user'], $db['pass']);
mysql_select_db($db['db'], $connection);
?

Posted: Mon Apr 23, 2007 12:39 am
by timvw
Under the assumption that OP has only one dbconnection it's not required to pass the handle around..

(My guess is that the user simply doesn't have create rights...)

Posted: Mon Apr 23, 2007 5:03 pm
by toasty2
No, I've installed a forum before in this database. My queries seem to do nothing. I manually created a table in my DB and i tried this code:

Code: Select all

require 'inc.php';
error_reporting(E_ALL);
$connection = mysql_connect($dbinfo_host, $dbinfo_user, $dbinfo_pass) or die('Couldnt connect to DB.');
mysql_select_db($dbinfo_db, $connection) or die('DB error.');

$query = "SHOW TABLES";
$tables = mysql_query($query);
echo $tables;
mysql_close($connection);
I get no errors, and it says "Resource id #3". What am I doing wrong? (I've never used MySQL before)

And yes, all those mysql-related variables I use have been defined.

Posted: Tue Apr 24, 2007 7:05 am
by feyd
You have to fetch the results like any other select query.