i am working on a project and i have faced trouble in connecting php with mysql. anyone out there who can give me a clue can contact me.
thanks
mekdes

Hi, all questions and replies should be done through the public forum -- so everybody can learn from the process.

Basic mysql connect with PHP where the database is on the local machine.

<?php
$host = 'localhost';
$user = 'root';
$pass = 'TopSecret';
$dbase = 'database';

$conn = mysql_connect( $host, $user, $pass ) or die( mysql_error() );

// here you are connected -- do something ...

expose_db( $conn, $dbase );

function expose_db ( $conn, $dbase ) {
  if ( $conn ) {
    mysql_query( "USE $dbase" );
    $tables = mysql_query( "SHOW TABLES" );
    while ( $table = mysql_fetch_assoc( $tables ) ) {
      $key = key( $table );
      print "<br>\nTable => ".$table[$key]."<br>\n";
      $fields = mysql_query( "DESCRIBE ".$table[$key] );
      while ( $field = mysql_fetch_assoc( $fields ) ) {
        foreach ( $field as $name => $value ) {
          if ( $value ) {
            print $name .' => '. $value .' :: ';
          }
        }
        print "<br>\n";
      }
    }
  } else {
    die( 'No connection available' );
  }
}
?>

If you are getting specific errors, let us know what they are.

Hope it helps ...

Try this one
<?
//connection
mysql_connect(localhost,root,vertrigo)or die("Error while conneciton");
//select the database
mysql_select_db("$db") or die(mysql_error());
?>

if u using the vertrigo server. Or u can post ur code.

This article has been dead for over six months. Start a new discussion instead.