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
https://forums.phpfreaks.com/topic/255021-create-table-doesnt-work-with-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.