Jump to content

CREATE TABLE doesn`t work with php


vandALOT

Recommended Posts

Hello.

I have problem creating mysql table with php but same code works when i use:  mysql --user=root mysql

 

Some time ago I made script for database installation for my website. It worked fine with php4 and older version of mysql(i dont remember which version).

 

Now I use:

PHP 5.3.8

MySQL 5.1.58

Fedora 14

 

Using mysql --user=root mysql  I created user and "myuser_db" database:

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%';
FLUSH PRIVILEGES;
CREATE DATABASE myuser_db;

 

 

My database installation script

 

install.db.php

$users = "
CREATE TABLE users
(
id INT( 6 ) AUTO_INCREMENT PRIMARY KEY ,
nickname VARCHAR( 20 ) NOT NULL ,
comment VARCHAR( 32 ) NOT NULL ,
password VARCHAR( 32 ) NOT NULL ,
role VARCHAR( 2 ) NOT NULL ,
email VARCHAR( 20 ) NOT NULL ,
registered TIMESTAMP NOT NULL ,
lastlogin TIMESTAMP NOT NULL ,
ip VARCHAR( 30 ) NOT NULL ,
aproved INT ( 2 ) NOT NULL ,
active INT ( 2 ) NOT NULL ,
code VARCHAR( 20 ) NOT NULL
)
ENGINE=InnoDB ";


$con = mysql_connect( 'localhost', 'myuser', 'myuser123' );
mysql_select_db( 'myuser_db' );
mysql_query( $users ); 

echo mysql_error();

mysql_close( $con );

The result is blank page.

 

 

When i paste this code in mysql console it works fine and I don`t know why CREATE TABLE doesn`t work with php.

 

 

I created table and added one user manualy and it works fine with this code:

$con = mysql_connect("localhost","myuser","myuser123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("myuser_db");

$result = mysql_query("SELECT * FROM users") or die(mysql_error());

while($row = mysql_fetch_array($result))
  {
  echo $row['nickname'] . " " . $row['email'];
  echo "<br />";
  }

mysql_close($con);

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.