Code Comments
Programming Forum and web based access to our favorite programming groups.Novice Learner wrote:
> I apologize if this is a very basic question.
>
> I just started learing PHP and MySQL, I am reading "PHP and MySQL" by Larr
y Ullman, I also have access to PHP 5 by Julie Meloni. I reached Chapter 6 o
f Ullman's book and got stuck.
>
> I have the following code:
>
> <?php
> //This file contains the database access information. This file also estab
lishes a connection
> //to MYSQL and selects the database.
> //Set the database access information as constants
> define ('DB_USER', 'masud');
> define ('DB_PASSWORD', 'masud');
> define ('DB_HOST', 'localhost');
> define ('DB_NAME', 'masud');
> //Make the connection and then select the database
> $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
> mysql_select_db(DB_NAME);
> ?>
>
> I have a normal MySQL user as "masud", whose password is also "masud" and
a database also called "masud". All this for learning purpose.
>
> I get the following error message:
>
> Fatal error: Call to undefined function mysql_connect() in C:\Program File
s\Apache Group\Apache2\htdocs\CTA\mysql_connect.php on line 13
>
> The books says:
> If you receive an error that claims mysql_connect() is an undefined functi
on, it means that PHP has not been compiled with MySQL support.
>
> I have been running a test script with <? phpinfo(); ?> and I get the results succ
essfully.
This is correct. In your phpinfo output, look for MySQL support. If you
find no mention of mysql in the output, it means mysql support is not
activated. PHP support was included by default in PHP 4, but is not in
PHP 5.
>
> I am running Windows XP with apache 2 server and PHP5 5.0.3
With PHP 5, you have to activate it yourself. MySQL support is no longer
supported by default. There are two steps:
1) In your php.ini file, you need to uncomment the extension line for
mysql. If you are using MySQL 4.0 or older, uncomment the line for
php_mysql.dll. If you are using MySQL 4.1 or higher, uncomment the line
for php_mysqli.dll
2) PHP needs to be able to find two files: php_mysql.dll (or
php_mysqli.dll) and libmysql.dll. If you installed from the zip file,
you have both. If you installed using the installer, you need to
download the zip file which contains these files. Copy both files into
your System32 directory.
Janet
>
> I would appreciate if you could help me in any way, including pointing me
to resources that can help get going.
>
> Thank you,
>
> Masud
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Read only the mail you want - Yahoo! Mail SpamGuard.
--
Janet Valade -- janet.valade.com
Post Follow-up to this messageJanet and Peter,
Thank you for your help. It worked and I was able to populate the database t
hrough the next script that was in the book. I am on my way to learning PHP
and MySQL. I hope it also works on my web hosting servers in a few days time
. Thank you again.
My New Year is starting in a great way.
Happy New Year to ALL.
Masud
Janet Valade <jvalade@eoni.com> wrote:
Novice Learner wrote:
> I apologize if this is a very basic question.
>
> I just started learing PHP and MySQL, I am reading "PHP and MySQL" by Larr
y Ullman, I also have access to PHP 5 by Julie Meloni. I reached Chapter 6 o
f Ullman's book and got stuck.
>
> I have the following code:
>
> //to MYSQL and selects the database.
> //Set the database access information as constants
> define ('DB_USER', 'masud');
> define ('DB_PASSWORD', 'masud');
> define ('DB_HOST', 'localhost');
> define ('DB_NAME', 'masud');
> //Make the connection and then select the database
> $dbc = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD);
> mysql_select_db(DB_NAME);
> ?>
>
> I have a normal MySQL user as "masud", whose password is also "masud" and
a database also called "masud". All this for learning purpose.
>
> I get the following error message:
>
> Fatal error: Call to undefined function mysql_connect() in C:\Program File
s\Apache Group\Apache2\htdocs\CTA\mysql_connect.php on line 13
>
> The books says:
> If you receive an error that claims mysql_connect() is an undefined functi
on, it means that PHP has not been compiled with MySQL support.
>
> I have been running a test script with and I get the results successfully.
This is correct. In your phpinfo output, look for MySQL support. If you
find no mention of mysql in the output, it means mysql support is not
activated. PHP support was included by default in PHP 4, but is not in
PHP 5.
>
> I am running Windows XP with apache 2 server and PHP5 5.0.3
With PHP 5, you have to activate it yourself. MySQL support is no longer
supported by default. There are two steps:
1) In your php.ini file, you need to uncomment the extension line for
mysql. If you are using MySQL 4.0 or older, uncomment the line for
php_mysql.dll. If you are using MySQL 4.1 or higher, uncomment the line
for php_mysqli.dll
2) PHP needs to be able to find two files: php_mysql.dll (or
php_mysqli.dll) and libmysql.dll. If you installed from the zip file,
you have both. If you installed using the installer, you need to
download the zip file which contains these files. Copy both files into
your System32 directory.
Janet
>
> I would appreciate if you could help me in any way, including pointing me
to resources that can help get going.
>
> Thank you,
>
> Masud
>
>
>
> ---------------------------------
> Do you Yahoo!?
> Read only the mail you want - Yahoo! Mail SpamGuard.
--
Janet Valade -- janet.valade.com
---------------------------------
Do you Yahoo!?
Jazz up your holiday email with celebrity designs. Learn more.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.