Jump to content

[SOLVED] Connecting to mysql db with PHP


chunk

Recommended Posts

Hi

I have apache 2.2.4 running and i have php 5.2.0 running.

When I use phpinfo() in a page, I get this screen:

[img]http://i26.photobucket.com/albums/c109/chunk38/phpinfo.jpg[/img]

This made me think that I had everything set up ok, however I cant connect to a database no matter what I do.

When I try and use this:

$conn = mysql_connect('localhost', 'userone', 'password') or die  ('Error connecting to mysql');

I just get a blank screen.

Can anyone help please?
Link to comment
https://forums.phpfreaks.com/topic/36498-solved-connecting-to-mysql-db-with-php/
Share on other sites

You cannot use mysql_* with the mysqli library you must use mysql[b][color=red]i[/color][/b]_* function set.

Your code should be like this:
[code=php:0]$conn = mysqli_connect('localhost', 'userone', 'password') or die  ('Error connecting to mysql');

echo "connection established";[/code]

Also when you are bugging scripts make sure you turn on display_errors directive in the php.ini and that error_reporting is set to E_ALL aswell.
  • 2 weeks later...

You cannot use mysql_* with the mysqli library you must use mysqli_* function set.

 

Your code should be like this:

$conn = mysqli_connect('localhost', 'userone', 'password') or die  ('Error connecting to mysql');

echo "connection established";

 

Also when you are bugging scripts make sure you turn on display_errors directive in the php.ini and that error_reporting is set to E_ALL aswell.

 

Yep. Installed mysql instead of mysqli, and it works fine. Thanks.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.