vandALOT Posted January 14, 2012 Share Posted January 14, 2012 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); Quote Link to comment https://forums.phpfreaks.com/topic/255021-create-table-doesnt-work-with-php/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 14, 2012 Share Posted January 14, 2012 What does the 'view source' of the blank page in your browser show? Does adding an echo 'testing....'; statement on that page output anything? Quote Link to comment https://forums.phpfreaks.com/topic/255021-create-table-doesnt-work-with-php/#findComment-1307629 Share on other sites More sharing options...
vandALOT Posted January 14, 2012 Author Share Posted January 14, 2012 'view source' showed me whole code, so I changed tags from <? ?> to <?php ?> and it everythink works ok now Just simple mistake and I wasted couple hours to fix it Thank you PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/255021-create-table-doesnt-work-with-php/#findComment-1307632 Share on other sites More sharing options...
PFMaBiSmAd Posted January 15, 2012 Share Posted January 15, 2012 Yep. More time wasted by php due to a lazy-way short-cut. Quote Link to comment https://forums.phpfreaks.com/topic/255021-create-table-doesnt-work-with-php/#findComment-1307858 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.