LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-16-2013, 06:12 AM   #1
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 117

Rep: Reputation: 3
cannot connect to mysql through php in ubuntu 10.04


I am using Ubuntu 10.04. Installed Apache 2.4, php 5.4 & Mysql 5.6 from source.
Apache installation path: /home/tarun/apache
Php Installation Path: /home/tarun/apache/php
Mysql Installation Path: /usr/local/mysql

httpd daemon is up and running ,php is called by Apache server when it encounters php file. I can login in Mysql through terminal & can edit, create tables.
PhpMyAdmin is also installed properly and it connects to database successfully.

But when I called mysql_connect() through php script then it throws Fatal error that mysql_connect is undefined. I tried to find mysql.so in apache,php and mysql installation folders but unable to find it."php -i" shows mysqli is enabled.Phpinfo() also shows Mysqli is enabled. "php -m" gives output:
[PHP Modules]
Core
ctype
date
dom
ereg
fileinfo
filter
hash
iconv
json
libxml
mysqli
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter

I am searching for solution for last 2-3 days but unable to find it , if someone knows what is the problem please help.

Last edited by tarunchawla; 04-16-2013 at 08:09 AM.
 
Old 04-16-2013, 09:57 PM   #2
dwduback
LQ Newbie
 
Registered: Nov 2005
Location: Glenview, IL
Posts: 10

Rep: Reputation: 1
Connection string and debug mode in PHP

Could you post your code up to the line that fails?

Read /etc/php5/cli/php.ini for instructions on how to get verbose error logging...check that file also for setting up paths...

updatedb and locate 'mysql.so' shows the file under /home/tarun/apache/php/php5/[version]/mysql.so?
 
Old 04-17-2013, 12:50 AM   #3
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 117

Original Poster
Rep: Reputation: 3
Quote:
Could you post your code up to the line that fails?
Fatal Error: Call to undefined function mysql_connect() in /home/tarun/apache/htdocs/hello.php

Quote:
Read /etc/php5/cli/php.ini for instructions on how to get verbose error logging...check that file also for setting up paths...
In /home/tarun/apache/php/etc/ there is only one file named pear.conf

Quote:
updatedb and locate 'mysql.so' shows the file under /home/tarun/apache/php/php5/[version]/mysql.so?
There is no php5 file folder in php folder after installation. Folders in /home/tarun/apache/php are :
bin
etc
include
lib
php
 
Old 04-17-2013, 02:03 AM   #4
eklavya
Member
 
Registered: Mar 2013
Posts: 633

Rep: Reputation: 141Reputation: 141
Install following package in your ubuntu and try again.
Code:
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
 
Old 04-17-2013, 03:22 AM   #5
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 117

Original Poster
Rep: Reputation: 3
Thanks eklavya , but this is not the solution for my problem.
 
Old 04-18-2013, 01:14 AM   #6
eklavya
Member
 
Registered: Mar 2013
Posts: 633

Rep: Reputation: 141Reputation: 141
Try
Code:
sudo apt-get install php-mysql
Does it say?
E: Unable to locate package php-mysql
 
Old 04-18-2013, 03:42 AM   #7
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 117

Original Poster
Rep: Reputation: 3
Eklavya Sirji , I don't want to use any repository of pre-compiled packages. I want to install each component seperately from source.
 
Old 04-18-2013, 10:11 AM   #8
jmc1987
Member
 
Registered: Sep 2009
Location: Oklahoma
Distribution: Debian, CentOS, windows 7/10
Posts: 891

Rep: Reputation: 119Reputation: 119
then compile --with-mysql

You have the mysqli extension compiled in

http://www.php.net/manual/en/mysql.installation.php
 
1 members found this post helpful.
Old 04-19-2013, 12:52 AM   #9
eklavya
Member
 
Registered: Mar 2013
Posts: 633

Rep: Reputation: 141Reputation: 141
Ok then try this
http://dev.mysql.com/doc/refman/5.1/...tallation.html
 
Old 04-24-2013, 12:46 AM   #10
tarunchawla
Member
 
Registered: Mar 2010
Location: New Delhi,India
Distribution: Ubuntu 14.04
Posts: 117

Original Poster
Rep: Reputation: 3
Problem is solved. I was using mysql_connect() which is included in mysql API not in mysqli API. Actually mysql provides three API through which connection can be established between php and mysql and are as follows:
1. mysqli
2. PDO
3. mysql.
mysql is depricated in php 5.5. mysqli is improved API and provides different set of API set than mysql, so if you have installed mysqli then you should use mysqli API functions not mysql .

http://www.php.net/manual/en/mysqlinfo.api.choosing.php
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GameCP, MySQL, PHP Connect PHP to MySQL? armsman Linux - Software 1 09-15-2011 11:22 AM
how to connect to mysql database using php in Apache on Ubuntu communication Linux - Newbie 4 06-02-2010 04:50 AM
Php cannot connect to mysql, mysql client can nfnitloop Linux - Server 1 04-24-2009 02:22 AM
can't connect php to mysql on RHEL5.0 in phpinfo page --without mysql is there vinayakbane Linux - Newbie 1 02-15-2009 12:47 AM
is there a client install for MySql so PHP can connect to MySQL Server? alar Linux - Software 8 07-03-2007 08:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration