Kaizen Maven Posted May 8, 2007 Share Posted May 8, 2007 I have just read this post: http://www.phpfreaks.com/forums/index.php/topic,95378.0.html, but this seems to apply for someone that has PHP installed on their computer or local machine. I am using a hosting server and my hosting company has PHP 5.0.4 installed. I am trying to work on creating tables for a database using the book "Beginning PHP, Apache, MySQL Web Development", and for some reason I can not seem to connect to the MySQL DB. Here is my code: <?php //Connect to MySQL DB. $connect = mysql_connect("localhost","php","mypasshere") or die ("Hey loser, this dog anit gonna hurt. You might want to check your server connection."); //Create the main database mysql_create_db("php") or die(mysql_error()); //Make sure our recently created database is the active one mysql_select_db("php"); //Create the "movie" table $movie = "CREATE TABLE movie ( movie_id int(11) NOT NULL auto_increment, movie_name varchar(255) NOT NULL, movie_type tinyint(2) NOT NULL default 0, movie_year int(4) NOT NULL default 0, movie_leadactor int(11) NOT NULL default 0, movie_director int(11) NOT NULL default 0, PRIMARY KEY (movie_id), KEY movie_type (movie_type,movie_year) ) TYPE=MyISAM AUTO_INCREMENT=4"; $results = mysql_query($movie) or die (mysql_error()); //Create "movietype" table $movietype = "CREATE TABLE movietype ( movietype_id int(11) NOT NULL auto_increment, movietype_label varchar(100) NOT NULL, PRIMARY KEY (movietype_id) ) TYPE=MyISAM AUTO_INCREMENT=9"; $results = mysql_query($movietype) or die(mysql_error()); //Create "people" table $people = "CREATE TABLE people ( people_id int(11) NOT NULL auto_increment, people_fullname varchar(255) NOT NULL, people_isactor tinyint(1) NOT NULL default 0, people_isdirector tinyint(1) NOT NULL default 0, PRIMARY KEY (people_id) ) TYPE=MyISAM AUTO_INCREMENT=7"; $results = mysql_query($people) or die (mysql_error()); echo "Movie Database Successfully Created!"; ?> I do have PHPMyAdmin, and I know I could do it through there, but I am trying to follow the book. I created the db php (cbxwebde_php) through my cPanel, and then created the username php (cbxwebde_php), then my password. Should I have done this first? I am getting this message: Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'php'@'localhost' (using password: YES) in /home/cbxwebde/public_html/php/createmovie.php on line 15 Hey loser, this dog anit gonna hurt. You might want to check your server connection. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/ Share on other sites More sharing options...
suttercain Posted May 8, 2007 Share Posted May 8, 2007 Are you using hosting with cPanel? If so "mysql_create_db function will not work on cPanel hosting." Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247818 Share on other sites More sharing options...
Kaizen Maven Posted May 8, 2007 Author Share Posted May 8, 2007 Yes I am using cPanel with my hosting. If so "mysql_create_db function will not work on cPanel hosting." So should I just create the tables, etc with my PHPAdmin??? Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247823 Share on other sites More sharing options...
mmarif4u Posted May 8, 2007 Share Posted May 8, 2007 The easy way is to use phpmyadmin. Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247828 Share on other sites More sharing options...
neel_basu Posted May 8, 2007 Share Posted May 8, 2007 Use PHPMyAdmin to create Database and I think you still can create Tables using PHP Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247829 Share on other sites More sharing options...
jitesh Posted May 8, 2007 Share Posted May 8, 2007 Try this may be helpful <?php $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"; } ?> Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247831 Share on other sites More sharing options...
Kaizen Maven Posted May 8, 2007 Author Share Posted May 8, 2007 Ok, so I just said the hell with it and I'll do i from PHPMyAdmin. Now I'm familiar with setting up tables and inputting the fields with their settings. But the book says to type this: $movie = "CREATE TABLE movie ( movie_id int(11) NOT NULL auto_increment, movie_name varchar(255) NOT NULL, movie_type tinyint(2) NOT NULL default 0, movie_year int(4) NOT NULL default 0, movie_leadactor int(11) NOT NULL default 0, movie_director int(11) NOT NULL default 0, PRIMARY KEY (movie_id), KEY movie_type (movie_type,movie_year) ) TYPE=MyISAM AUTO_INCREMENT=4"; I know how to convert the movie_id, name, type, leadactor, and director into fields. But what about the PRIMARY KEY & KEY. In PHPMyAdmin what do I make the KEY? I see icons for Primary (with Key), also for Index, Unquie, and Fulltext. But do I make the movie_id field and the movie_type and year the primary key? Or just one? Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247838 Share on other sites More sharing options...
mmarif4u Posted May 8, 2007 Share Posted May 8, 2007 U can keep multiple primary keys in table. Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247840 Share on other sites More sharing options...
Kaizen Maven Posted May 8, 2007 Author Share Posted May 8, 2007 U can keep multiple primary keys in table. Ok, so basically PRIMARY KEY & KEY are the same thing, and I can set them both in the PHPmyAdmin I just tried to make the movie_id, movie_type, and movie_year the primary key and my PHPAdmin said Error Multiple primary key defined Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247845 Share on other sites More sharing options...
Kaizen Maven Posted May 8, 2007 Author Share Posted May 8, 2007 Side Note: I just made all the "_id" for each table a primary key, so that I can move on with the tutorial. Hopefully that will work, but I'll come back if I have any questions. Link to comment https://forums.phpfreaks.com/topic/50442-another-phpmysql-connectivy-problem/#findComment-247855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.