Solved

mysql php error when connecting

Posted on 2011-03-13
10
376 Views
Last Modified: 2012-05-11
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);
?>
0
Comment
Question by:enigma1234567890
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:nidash
ID: 35120795
Need more infomration, how's you php installed? on windows or linux? do you have php_mysql extension enabled in php.ini?
0
 

Author Comment

by:enigma1234567890
ID: 35120896
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
 

Author Comment

by:enigma1234567890
ID: 35120898
linux centos but compiled by hand using

 ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql-dir=/var/local/mysql
make
0
 

Author Comment

by:enigma1234567890
ID: 35120927
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
 
LVL 2

Accepted Solution

by:
nidash earned 500 total points
ID: 35121118
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 28

Expert Comment

by:chilternPC
ID: 35121135
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
 

Author Comment

by:enigma1234567890
ID: 35121145
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
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 35121169
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
 
LVL 28

Expert Comment

by:chilternPC
ID: 35121237
if you are building the system from scratch
follow one of the install for LAMP
see http://www.lamphowto.com/
0
 

Author Comment

by:enigma1234567890
ID: 35123499
recompiled php and it worked

./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-libdir=lib64
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now