mysql php error when connecting

I am trying to get mysql and php working.  i get the following when i try connecting to home page

Fatal error: Call to undefined function mysql_connect() in /usr/local/apache2/htdocs/includes/connecttodb.php on line 5

not my connecttodb.php file looks as follows

<?php
$dbhost = 'localhost:3306';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');

$dbname = 'test';
mysql_select_db($dbname);
?>
enigma1234567890Asked:
Who is Participating?
 
nidashCommented:
see

http://www.centos.org/modules/newbb/viewtopic.php?viewmode=flat&topic_id=3952&forum=28

Also in your php.ini find lines were it says extensions, and make you have the mysql extension available in the extension dir after the yum install according to previous url.

extension_dir = "/usr/lib/php/modules"

> then have /etc/php.ini file:
> extension=mysql.so
> extension=mysqli.so

restart apache and try
0
 
nidashCommented:
Need more infomration, how's you php installed? on windows or linux? do you have php_mysql extension enabled in php.ini?
0
 
enigma1234567890Author Commented:
installed on linux

not sure how to check for php_mysql extensions.  How do i enable this

php info says

Loaded Modules       core mod_authn_file mod_authn_default mod_authz_host mod_authz_groupfile mod_authz_user mod_authz_default mod_auth_basic mod_include mod_filter mod_log_config mod_env mod_setenvif mod_version prefork http_core mod_mime mod_status mod_autoindex mod_asis mod_cgi mod_negotiation mod_dir mod_actions mod_userdir mod_alias mod_so mod_php5
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
enigma1234567890Author Commented:
linux centos but compiled by hand using

 ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql-dir=/var/local/mysql
make
0
 
enigma1234567890Author Commented:
php.ini says

[MySQL]
; Allow or prevent persistent links.
mysql.allow_persistent = On

; Maximum number of persistent links.  -1 means no limit.
mysql.max_persistent = -1

; Maximum number of links (persistent + non-persistent).  -1 means no limit.
mysql.max_links = -1

; Default port number for mysql_connect().  If unset, mysql_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysql.default_port = 3306

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /var/lib/mysql/mysql.sock

; Default host for mysql_connect() (doesn't apply in safe mode).
mysql.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysql.default_user =

; Default password for mysql_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysql.default_password =
; Maximum time (in secondes) for connect timeout. -1 means no limit
mysql.connect_timeout = 60

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Errors will be displayed.
mysql.trace_mode = Off

[MySQLi]

; Maximum number of links.  -1 means no limit.
mysqli.max_links = -1

; Default port number for mysqli_connect().  If unset, mysqli_connect() will use
; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the
; compile-time value defined MYSQL_PORT (in that order).  Win32 will only look
; at MYSQL_PORT.
mysqli.default_port = 3306

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysqli.default_socket =

; Default host for mysql_connect() (doesn't apply in safe mode).
mysqli.default_host =

; Default user for mysql_connect() (doesn't apply in safe mode).
mysqli.default_user =

; Default password for mysqli_connect() (doesn't apply in safe mode).
; Note that this is generally a *bad* idea to store passwords in this file.
; *Any* user with PHP access can run 'echo get_cfg_var("mysqli.default_pw")
; and reveal this password!  And of course, any users with read access to this
; file will be able to reveal the password as well.
mysqli.default_pw =

; Allow or prevent reconnect
mysqli.reconnect = Off

[mSQL]
; Allow or prevent persistent links.
msql.allow_persistent = On

; Maximum number of persistent links.  -1 means no limit.
msql.max_persistent = -1

; Maximum number of links (persistent+non persistent).  -1 means no limit.
msql.max_links = -1


0
 
Peter HartCommented:
create a file called phpinfo.php on the root of your web site
with the following content:

<?php
    phpinfo();
?>

then run the file, in the browser using   http://localthost/phpinfo.php
see what it says

0
 
enigma1234567890Author Commented:
the link taltk asbout installing via yum but you only has php support for 5.16 I installed the latest php version 5.2.17

I think the extensions directory you mention is only from a windows box my php.ini file doesnt contain the word extensions,  it might exist if i can find out how to install php5.2.17 without using yum
0
 
Sudaraka WijesingheWeb Application ProgrammerCommented:
see if phpinfo() shows you the MySql module details. if not, that means MySql is not loaded and/or compiled properly.
Try recompiling PHP and make sure it completes without any critical errors.

You can also, install Apache, PHP and MySql from RPMs which would save you the hassle of going through issues like this.
0
 
Peter HartCommented:
if you are building the system from scratch
follow one of the install for LAMP
see http://www.lamphowto.com/
0
 
enigma1234567890Author Commented:
recompiled php and it worked

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-libdir=lib64
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.