Does anyone know how to retrieve 开发者_如何学Pythona piece of data and display the results in php file? A similar query that I would enter is something like this:
SELECT 'email' FROM 'users' WHERE 'username' = 'bob'
Thus, the result would be just the email.
Thanks,
Kevin
To connect
$con = mysql_connect("host","userName","passWord");
if (!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("dbNameToSelect", $con);
To query
$result = mysql_query("SELECT `email` FROM `users` WHERE `username` = 'bob'");
while($row = mysql_fetch_array($result)){
// do stuff with $row['colName']
}
To close connection mysql_close($con);
You need to connect and fetch data from a database, like mysql. Check the code below:
$server = "localhost";
$username = "root";
$password = "";
$database = "mysampledb";
mysql_connect($server, $username, $password);
mysql_select_db($database);
$result = mysql_query("SELECT email FROM users WHERE username = 'bob'") or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
echo $row["email"];
}
See also: http://www.php.net/manual/en/mysqli.query.php There are a few good examples
精彩评论