dijai jijfs
dijai jijfs

Reputation: 1987

iPage Connect PHP to my Database

I am new to programming. I have a website on iPage. Now, I am learning PHP and one of the things I am learning is to connect PHP to mySql database. I am using the following: mysql_connect(host name, username, password)

My question is, why I am not getting an error? no matter what username and password and even host name i enter, it just accepts it!

This is the code I am trying (the username and password are just as example)

<?php
mysql_connect('ipage','admin','password');
echo 'Connected!';
?>

when I run it, it just says connected even though my username and password are not admin, password.

Upvotes: 0

Views: 4542

Answers (2)

Lkopo
Lkopo

Reputation: 4843

Use mysqli_*, beacuse mysql_* is deprecated and will be removed in the future:

$conn = mysqli_connect('localhost', 'username', 'password');
if(mysqli_connect_errno($conn))
{
    die('Error in connection to MySQL: ' . mysqli_connect_error());
}
else
{
    echo 'Connected successfully';
}

Upvotes: 2

user123_456
user123_456

Reputation: 5805

You are not checking if you are connected. You need to use something like this:

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);

My suggestion is to start reading some docs, they have some great examples and you can really learn a lot. DOCUMENTATION

Upvotes: 0

Related Questions