Can't use a php script with simple mysql connect function

Hey,

I just started using linode and so far I have followed the guides to set up a webserver and stuff like that. Also got a domain: sqdejan.com. I have installed Apache, mysql and php. When I upload php files with simple php code it will show. But once I put in some mysql code it can't even load the page: sqdejan.com/mysqlconnect. At least it should say failed to connect. I have tried it on another server where the script works fine. What am I doing wrong? Why can't it read mysql code?

Thanks

7 Replies

It could be many things:

1. You may not have created the database you're trying to access.

2. You may not have created a MySQL user and password.

3. You may not have given the MySQL user the appropriate rights to access the database.

4. Your web app may not be configured to use the right server.

5. Your web app may not be configured to use the right database.

6. Your web app may not be configured to use the right username and password.

You can test 1-3 by logging in to your Linode and running the following command, substituting the appropriate values:

mysql -u [username] -p [database_name]

You should then be able to issue SQL commands like SHOW TABLES; or *SELECT * FROM [table_name] LIMIT 5;*.

Items 4-6 depend on what parameters you're using in your PHP code.

There could also be errors in the code; perhaps it was written for a different version of PHP than what is running on your Linode. Check your PHP error logs.

sqdejan,

MSJ

@MSJ

Ye, I have set it up to display errors according to the guide:

maxexecutiontime = 30

memory_limit = 128M

errorreporting = ECOMPILEERROR|ERECOVERABLEERROR|EERROR|ECOREERROR

display_errors = On

log_errors = On

error_log = /var/log/php.log

register_globals = Off

and this is the very simple code I am running:

mysql_connect("localhost", "lol", "lol");

?>

On another server I get the message in the browser:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'lol'@'localhost' (using password: YES) in /var/www/web10/html/timtherobot/mysqlconnect.php on line 2

But the problem is I dont get that on my own webpage. It is like its not even trying to connect.

@Vance

Ye I got database and users etc.. But the problem is my, atleast I think, is that it does not execute the code, all I want it to say is the same error as mentioned above. Just to indicate that it at least trying to connect to mysql. But my browser just says "Server fail" (roughly translated)

I can retrieve from the error_log

PHP Fatal error: Call to undefined function mysql_connect() in /root/public/sqdejan.com/public/mysqlconnect.php on line 2

But I have installed php5_mysql on my server.

I am so lost :(

Restart Apache (or php5-fpm if you're using that).

Already done that - doing that everytime I make a change. Also tried to restart mysql! I have just followed the guide on how linode is suggesting that you set up a webserver! This is so wierd.

@sqdejan:

I can retrieve from the error_log

PHP Fatal error: Call to undefined function mysql_connect() in /root/public/sqdejan.com/public/mysqlconnect.php on line 2

But I have installed php5_mysql on my server.

That is strange. While mysql_connect() is deprecated, it should still be available for use.

It's possible you have conflicting packages from different repositories. Can you list the packages you have installed? Try yum info installed 'mysql' 'php' on Fedora/CentOS or aptitude -F '%c %?p# %?v# %?t#' search '~n(mysql|php)' | grep '^i' on Debian/Ubuntu.

Not to be totally silly, but do you have the mysql module uncommented in php.ini?

Best thing, share phpinfo() and the php.ini you've seen listed as used in the phpinfo output.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct