Connect to MySQL with PHP


<h1>MySQL Test Code Results</h1>
<p><table border="1">
<tr>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
</tr>

<?php

// Configuration Information and Definitions

$mysql_host = 'MySQL Server Name';
$mysql_user = 'DB Login';
$mysql_pass = 'DB Password';
$mysql_db = 'DB Name';
$query = 'SELECT * from table1';

$con = mysqli_connect($mysql_host, $mysql_user, $mysql_pass) or die("Connection to MySQL-server failed!");

mysqli_select_db($con, $mysql_db) or die("Selection of database $mysql_db failed!");

$result = mysqli_query($con, $query) or die("Invalid Query, " . mysql_error());

while( list( $pkid, $fname, $lname ) = mysqli_fetch_row($result) ) {
printf("<tr><td>%d</td><td>%s</td><td>%s</td></tr>", $pkid, $fname, $lname);
}

?>
</table>
<p />
<b>End MySQL Test Code Results</b>
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

SQL server- network related or instance-specific error happened while connection establishing

  Instance-specific or network related error happening while connecting to SQL server   Please...

OleDB connection string examples

OleDB connection string examples MS Access (Jet) "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA...

Do you allow custom COM components?

Do you allow custom COM components? We are not offering to install the custom COM components...

Error when accessing a WCF services

Error when accessing a WCF services Error when accessing a WCF service: "IIS specified...

How to cache static contents to client with UseMaxAge?

You can consider to caches static contents to the client with UseMaxAge if your website has too...

Powered by WHMCompleteSolution