Jump to content

Newbie Help please connecting to my sql


chaddsuk

Recommended Posts

Hi im new to PHP and am trying to connect to my MYSQL which is setup on my local machine using apache server.

 

I am using the following code to try and connect but all i seem to get is a blank page...

 

<?php

$dbhost = 'localhost';

$dbuser = 'php';

$dbpass = '*****';

 

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die

('Error connecting to mysql');

 

$dbname = 'chadd';

mysql_select_db($dbname);

 

echo "connection made";

 

?>

 

anyone any idea what im doing wrong?

 

cheers

 

chris

Link to comment
Share on other sites

<?php
$dbhost = 'localhost';
$dbuser = 'php';
$dbpass = '*****';
$dbname = 'chadd';

function connectdb($host, $user, $pass, $db)
{
mysql_connect($host, $user, $pass);
mysql_select_db($db) or die('Unable to select .com database!');

        echo 'Successful Connection';
}

connectdb($dbhost, $dbuser,$dbpass,$db);


?>

 

Not sure why yours won't connect.. .try this one

Link to comment
Share on other sites

hi im using MySQL 5.0.45, i added the user correctly and can log in fine through command prompt but just dont seem to be able to connect through PHP?

 

Thanks for your help guys, this is a really great forum, much better than the others ive been on :)

 

 

Link to comment
Share on other sites

what is the output from this script:

 

 

<?php
  ini_set('display_errors','on');
  $dbhost = 'localhost';
  $dbuser = 'php';
  $dbpass = '*****';
  $dbname = 'chadd';

  $conn = mysql_connect($dbhost, $dbuser, $dbpass)
    or die('Error connecting to mysql');

  mysql_select_db($dbname)
    or die('Error selecting database');

  echo "connection made";
?>

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.