LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-17-2008, 05:07 AM   #1
shan_nathan
Member
 
Registered: Jun 2007
Location: India
Distribution: Redhat
Posts: 137

Rep: Reputation: 15
Cannot connect to mysql database using php script


Dear all,

I am using suse linux 10.1. I tried to connect my local mysql database using php web page.

This is my php & mysql version

Linux # php5 -version
PHP 5.1.2 (cli) (built: Oct 5 2006 13:17:20)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies

Linux # php5 -version
PHP 5.1.2 (cli) (built: Oct 5 2006 13:17:20)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
Linux #

And this is the script i am using to connect mysql database

<?php
$link = mssql_connect('localhost', 'root', 'mypassword');
if (!$link) {
die('Could not connect: ' . mssql_error());
}
echo 'Connected successfully';
mssql_close($link);
?>

When i try to access this is webpage it is showing blank only. I shutdown my sql server and again try to connect. But still i am getting the same blank screen. no error or something else.

Can someone help me in this issue.

Thanks in advance
Shan
 
Old 10-17-2008, 05:21 AM   #2
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Rep: Reputation: 37
Here's your problem:
$link = mssql_connect('localhost', 'root', 'mypassword');
it's not mssql_connect but mysql_connect.
I advise you turn on error reporting in php.ini which is located in /etc, if you think it's a security issue to turn it on, turn it on only when you're fixing a problem and then disable it afterwards. Don't forget to restart Apache after making the change in php.ini file.

And I see you're using mssql everywhere in the script, I presume you're migrating from MSSQL? Use mysql everywhere in the script.
 
Old 10-17-2008, 05:24 AM   #3
shan_nathan
Member
 
Registered: Jun 2007
Location: India
Distribution: Redhat
Posts: 137

Original Poster
Rep: Reputation: 15
Dear Tux-Slack,

Sorry for the not working script. I wrongly copied that script. this is the script i am using


<?php

$dbcnx = mysql_connect('localhost', 'root', 'mypasswd');
$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');
if (!$dbcnx) {
echo( '<p>Unable to connect to the ' .
'database server at this time.</p>' );
exit();
}
?>


After enabling the error reporting i got the following error

Fatal error: Call to undefined function mysql_connect() in /srv/www/htdocs/test.php on line 3

Can you advice me in this issue.

Thanks,
Shan

Last edited by shan_nathan; 10-17-2008 at 05:37 AM. Reason: update
 
Old 10-17-2008, 07:33 PM   #4
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
It looks like you need to install the php-mysql package. Go to your package manager and look for the various php packages that are available.
 
Old 10-17-2008, 11:58 PM   #5
Tux-Slack
Member
 
Registered: Nov 2006
Location: Slovenia
Distribution: Slackware 13.37
Posts: 511

Rep: Reputation: 37
Exactly, you're missing the PHP mysql functions, what distro are you using?

Edit:
Sorry for being blind.
I think SuSE uses yust if I'm not wrong, if I am someone please correct me. Look for the package php-mysql or something like that, just like graemef said.

Last edited by Tux-Slack; 10-17-2008 at 11:59 PM.
 
  


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
Cannot connect to mysql database using php in Apache on Centos 5.1 OS homyangcha Linux - Newbie 1 06-30-2008 08:18 AM
Trying to get PHP to connect to a MySQL Database bassplayer69 Programming 16 03-13-2008 09:27 PM
LXer: Backing up your MySQL database using your web browser and a PHP script LXer Syndicated Linux News 0 04-21-2007 10:16 PM
PHP Script for Importing vCards into a MySQL Database? amocjr Linux - Software 1 01-20-2007 03:54 PM
cannot connect to mysql database from php rocordial Linux - Software 2 08-21-2005 02:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:46 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