ristenk1
ristenk1

Reputation: 433

mysql_connect.. no connection and no error

This seems like it should be so easy but I am not getting an error or any result:

$connection = mysql_connect("phpexamplesite.db.4211592.hostedresource.com", "username", "password");
if(!$connection) {

    die("Database connection failed: " . mysql_error());
}

//2. Select a database to use

$db_select = mysql_select_db("username", $connection);
if(!$db_select){
die("Database selection failed: " . mysql_error()); 

Any ideas?

THanks:)

sorry about that... I did put the query in:

// 3. Perform database query
            $result = mysql_query("SELECT * FROM subjects", $connection);
            if(!$result){
                die("Database query failed: " . mysql_error());
            }

            //4. Use returned data

            while($row = mysql_fetch_array($result)) {
                echo $row["menu_name"]. " ".$row["position"]. "<br />";
            }

            ?>

 <?php
        //5. Close connection

        mysql_close($connection);

?>

I'm not getting any error or results on the page...

Upvotes: 1

Views: 1306

Answers (2)

user851031
user851031

Reputation:

It could be from a syntax error. You are missing a closing brace in the first code snippet in

if(!$db_select)
{
  die("Database selection failed: " . mysql_error()); `
**}**

Try running your file from the command line through php test.php

Some servers (Apache) are configured to not output anything if there is a syntax error.

Upvotes: 0

Sebas
Sebas

Reputation: 21532

You probably just don't have any result from the select statement.

Upvotes: 1

Related Questions