MySQL Selects
Added by astuffedtiger on May 16, 2017 18:45
<?php
/* This will easily grab the result from a MySQL row instead of having to go through 3-4 lines of PHP code we can do it in about 2. I like this more. Need to implement across sites. */
	
$database_host = "";
$database_user = "";
$database_password = "";
$database_name = "";

/* Make a connection to the database */

$con = mysql_connect("$database_host","$database_user","$database_password");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

$db = mysql_select_db($database_name);
if(!$db) {
	die("Unable to select database");
}

$result = mysql_query("SELECT name FROM customers WHERE id='1'");
if (!$result) {
		die('Could not query:' . mysql_error());
}
$customername = mysql_result($result, 0);
echo "Hello, $customername.";
?>

Comments