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
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.
Link to comment
Share on other sites

  • 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.