Jump to content

MySQL 5 / PHP mysql_connect


stuartgpalmer

Recommended Posts

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:

<?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.
Link to comment
https://forums.phpfreaks.com/topic/34304-mysql-5-php-mysql_connect/
Share on other sites

I don't know if this will help, but this is what I use to connect to mine:

[code]<?php
  $con = mysql_connect("","","") or die('Error: <br />'. mysql_error());
if (!$con)
  die("Error: ". mysql_error());

mysql_select_db("database", $con) or die("Error: ".mysql_error());
?>
[/code]

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.