[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

mysql php error when connecting

Posted on 2011-03-13
10
Medium Priority
?
415 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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
 
LVL 29

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 29

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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 16 hours left to enroll

829 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