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

Recommended Answers

All 3 Replies

Member Avatar for langsor

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 ...

Please post your code or else follow langsor's example.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.