Solved

mysql php error when connecting

Posted on 2011-03-13
10
383 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP_POST() error message 9 44
html input type 3 22
Making register page log you in after registration is complete. 2 14
Scope of $_SESSION 17 30
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

920 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

13 Experts available now in Live!

Get 1:1 Help Now