MySQL 5 connection pron mysql_real_connect

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
stuartgpalmer
Forum Newbie
Posts: 1
Joined: Mon Jan 15, 2007 1:53 pm

MySQL 5 connection pron mysql_real_connect

Post by stuartgpalmer »

Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


My host recently upgraded me from MySQL 4.1 to 5. I have been using the mysql_connect command to connect from PHP but it has now been depreciated. Though there is online documentation for this command in mysql terms, I cannot find a PHP/MySQL solution.

This is my code:

Code: Select all

<?php
$user="my_username";
$host="localhost";
$password="my_password";
$database ="my_database";
$connection = mysql_connect($host,$user,$password)
   or die ("Couldn't connect to the database.");
$db = mysql_select_db($database,$connection)
   or die ("Couldn't select database");
?>
Can anyone tell me how to turn this into a mysql_real_connect script which works with MySQL 5? I will post a jar of <a href="http://www.roystonpickles.co.uk">my finest chutney</a> to anyone who cracks this. Many thanks, I'm going spare.


Jcart | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

What exactly is wrong with your code. mysql_connect() is certainly not deprecated.

Errors?

Sounds like you have upgraded your version of PHP to > 5, which does not have mysql enabled by default. Uncomment

Code: Select all

#extension=mysql.so
in your php.ini. (remove the pound) to enable the mysql extension, then restart your server.
I will post a jar of <a href="http://www.roystonpickles.co.uk">my finest chutney</a> to anyone who cracks this. Many thanks, I'm going spare.
Our help is free around here. Thanks for the offer, but it unnecessary. Unless...Image
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

If the error message is
Client does not support authentication protocol requested
by server; consider upgrading MySQL client
have a read of http://dev.mysql.com/doc/refman/5.0/en/old-client.html
If your provider is installing and maintaining php (not a do-it-yourself root server) also send a mail with the problem description and this link to your provider so they can fix it.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Jesus Christ! There is a man offing chutney for programming work!

* ole thinks about a sandwich he made himself earlier today using chutney


* ole drools over his keyboard

What? Oh yeah. I do like chutney very much. :D
Post Reply