Creating/Connecting to a mysql database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
greeneel
Forum Commoner
Posts: 47
Joined: Wed Jul 30, 2003 5:19 pm

Creating/Connecting to a mysql database

Post by greeneel »

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi,

I am learning php and came across this script... (Script Attached) while using the book. Beginning PHP, Apache, Mysql Web Development.

and im getting this error: and i have a few questions

Code: Select all

Fatal error: Call to undefined function: mysql_connect() in c:\wamp\www\createmovie.php on line 4
Now I don`t see why this isn`t working because in the book it said to download:PHP: 4.3.3, Apache: 2.0.47, Mysql: 4.0.15a and i`m following the book. Now I installed php 4.3.3, apache 2.0.47 but wasn`t able to find mysql 4.0.15a binary for windows so I installed mysql 5 most recent stable version as of today.
I am confused because following this book gets me nowhere when running this script but according to them it should work..Is it because i never got the mysql 4.0.15a? don`t see how a person writes a book to teach you something and seem to assume u know something about it already..

Can anyone tell me how to get around this connect problem ini this script?
Does anyone have any other ideas on books to point me to that works?
And does a mysql 4.0.15a exist for windows?

Code: Select all

<?php
//Connect to <Mysql; note we`ve used our own parameters- you should
//use your won for hostname, user and password
$connect = mysql_connect("localhost", "root", "mysqlpass") or
	die ("Hey loser, check your server connection.");
	
//Create the mail database
	mysql_create_db("donda")
	or die(mysql_error());
	
//make sure our recently created database is the active one
mysql_select_db ("donda");

//create "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());
		
//Creat "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!";
?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I can't really think of anything that'd be at issue so...
http://downloads.mysql.com/archives.php?p=mysql-4.0
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Doesn't the MySQL module have to be loaded in either Apache or PHP for that function to work?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

in PHP 4, MySQL was compiled into PHP by default.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Found this through google:
I was aware that mysql_connect has been discontinued in C API, but why am I getting this error? I found that mysql_connect has been deprecated in favor of mysql_real_connect(). While that doesn't solve our issue at hand, I do want to take a moment to point out that Ingo Tomahogh has a good tip posted on http://dev.mysql.com about migrating your code from using mysql_connect() to mysql_real_connect function. To put it in Ingo's words:


If you need to compile old programs still using this function, you might want to add the following macro definition to your programs (possibly via the compiler's command line) so you needn't change all calls to mysql_connect() :
http://mysqldatabaseadministration.blog ... ll-to.html
Post Reply