Newbie713 Newbie713 - 1 year ago 84
PHP Question

Failing testing database connection in php

I've set up a database using MAMP.
When I try the following test, I only receive a blank page. Fairly new to this, and I've tried different suggestions found on the web with no luck.
Tried using both port and socket.

$user = 'root';
$password = 'root';
$db = 'test';
$host = 'localhost';
$port = 3306;
$socket = "/Applications/MAMP/tmp/mysql/mysql.sock";

$link = mysql_connect(
$db_selected = mysql_select_db(

if (!$link){
echo "ERROR";
else {
echo "Success";


Answer Source

Would you like to try PDO ?!

    $dsn = "mysql:host=localhost;dbname=databasenamehere";
    $user = 'root';
    $pass = '';
    $option = array(

    try {
        $connect = new PDO($dsn, $user, $pass,$option);

    catch (PDOException $r) {
        echo 'Failed' . $r->getMessage();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download