MySQL Forums
Forum List  »  PHP

Unable to connect. Check your connection parameters
Posted by: naveen ganpat
Date: March 14, 2015 06:58AM

Hi Guys,

I am learning from a book to code in php and mysql. However, the book assumes that I will be practising on my PC.


1. The code says connect to mysql using the username 'bp6am' and password 'bp6ampass'.
2. I went back to the cpanel and tried to create these usernames.

Problem: mysql will only create username if it can attach it to a database.

Hoewever, the book code says "'CREATE DATABASE IF NOT EXISTS moviesite".
My questions:
1. Should I create the database "moviesite" first?
2. Is there a way to create username in mysql without attaching this to a specific database?

thanks,

N

Please see code below:

<?php
//connect to MySQL
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or
die ('Unable to connect. Check your connection parameters.');

//create the main database if it doesn't already exist
$query = 'CREATE DATABASE IF NOT EXISTS moviesite';
mysql_query($query, $db) or die(mysql_error($db));

//make sure our recently created database is the active one
mysql_select_db('moviesite', $db) or die(mysql_error($db));

//create the movie table
$query = 'CREATE TABLE movie (
movie_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
movie_name VARCHAR(255) NOT NULL,
movie_type TINYINT NOT NULL DEFAULT 0,
movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0,
movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0,
movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0,

PRIMARY KEY (movie_id),
KEY movie_type (movie_type, movie_year)
)
ENGINE=MyISAM';
mysql_query($query, $db) or die (mysql_error($db));

//create the movietype table
$query = 'CREATE TABLE movietype (
movietype_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
movietype_label VARCHAR(100) NOT NULL,
PRIMARY KEY (movietype_id)
)
ENGINE=MyISAM';
mysql_query($query, $db) or die(mysql_error($db));

//create the people table
$query = 'CREATE TABLE people (
people_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
people_fullname VARCHAR(255) NOT NULL,
people_isactor TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,

PRIMARY KEY (people_id)
)
ENGINE=MyISAM';
mysql_query($query, $db) or die(mysql_error($db));

echo 'Movie database successfully created!';
?>

Options: ReplyQuote


Subject
Written By
Posted
Unable to connect. Check your connection parameters
March 14, 2015 06:58AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.