LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 04-26-2004, 01:05 AM   #1
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Rep: Reputation: 15
php can connect mysql, but can't do anything else?


hey everyone:

First off, my apologies for the really long post, and if it would be more
appropriate in another forum, please let me know so I'll know next time.


I'm making a web app with php and mysql. Using the default versions
which came with Slack 9.1.
For some reason, i can get php to make a connection with mysql,
but none of the other functions seem to work, even though I'm
connecting as root.

Here is the code (just a test to demonstrate the problem):

<html> <body>
<head> <title></title> </head>


<?php
$link= mysql_connect('localhost', mysqlu(), mysqlp()) ||
exit("couldn't connect");

echo 'db connected';

$db_sel= mysql_select_db("nonexistentdb", $link);

if( !($db_sel) )
echo mysql_errno( $link ) . ": " . mysql_error( $link );
?>
</body> </html>

The mysqlu() and mysqlp() return 'root' and 'rootpassword'.
This is the same example as in the php manual (html) page
for msyql_select_db.

The mysql_select_db is the function i used in this case, but
none of my other mysql functions, other than connect,
seem to be working.

Below is the output followed by some version info, as well
as php.ini. I also tried changing the default socket path
line in php.ini to:
/var/run/mysql/mysql.sock
and restarting the system. But the output was exactly
the same.

Thanks for all your help!


----------------------------------------------------------------------

db connected

:

----------------------------------------------------------------------

below is the actual html (output) source:


<html>

<head> <title></title> </head>

<body>
db connected<br><br>:
</body>
</html>

-----------------------------------------------------------------------

here is some version info:

PHP 4.3.3 (cgi-fcgi) (built: Sep 12 2003 00:18:31)

mysql Ver 12.21 Distrib 4.0.15a, for slackware-linux (i486)

------------------------------------------------------------------------

here are some lines from php.ini

; Load the MySQL module by default. Comment this out if you don't use MySQL.
extension=mysql.so

[SQL]
sql.safe_mode = Off


[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 =

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =

; 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 limimt
mysql.connect_timeout = 60

; Trace mode. When trace_mode is active (=On), warnings for table/index scans and
; SQL-Erros will be displayed.
mysql.trace_mode = Off
 
Old 04-26-2004, 03:28 PM   #2
msound
Member
 
Registered: Jun 2003
Location: SoCal
Distribution: CentOS
Posts: 465

Rep: Reputation: 30
if you're new to php and mysql I would suggest logging in to mysql locally if you have direct access to the server. just do mysql -u username -p and enter your password.

Once you connect locally try out a few functions like creating databases and tables. Then insert some values into the tables.

The reason I suggest this is becuase I learned mysql while I learned php, most of the time the mysql errors came becuase my php syntax was incorrect. By working with mysql directly, you can get used to the syntax and plug it in to php a little more easily.

If mysql works locally and you still cant get it to work with php scripts, try looking for php-mysql packages. I know with redhat you have to install a specific package to make php and mysql to work together. I've never used slackware but if its like redhat, you may not have all of the packages installed to get the 2 apps to run together.

you're the worst character ever towlie

Last edited by msound; 04-26-2004 at 03:54 PM.
 
Old 04-26-2004, 04:17 PM   #3
towlie
Member
 
Registered: Apr 2004
Location: U.S.
Distribution: slackware 10.0
Posts: 110

Original Poster
Rep: Reputation: 15
msound:

Thanks for the response.

I can log in to mysql in the console, and everything works great there. I have a functional db with 8 or so tables.

However, with trying to connect with php from the cgi-module, mysql_connect() is all I can get to work. I can't even get mysql_errno() and mysql_error() working, so I don't even know where to start looking for a problem.

Instead, does anyone know if there's a log file I could look at, perhaps one created by php, mysql, or even apache?

As for the packages, i'm using the defaults of what the slackware guys put on here, so I don't know why they wouldn't work. Kind of hesitant to reinstall something myself since almost everything else from the install cd seems to be working.

I will look around for some packages though.

And remember ... if you're going to the pool or the beach, dont forget to bring a towel!
 
  


Reply



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 from php rocordial Linux - Software 2 08-21-2005 02:05 PM
PHP can't connect to MySQL westchester Linux - Software 13 07-02-2005 10:45 PM
PHP Can Not Connect To MYSQL ombill Fedora 4 09-06-2004 01:24 PM
Can't connect to MySQL server using PHP Lars79 Linux - Newbie 3 08-05-2004 03:13 PM
Can't connect MySQL through PHP mac Programming 1 02-18-2002 09:23 AM

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

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