Popular Posts

Friday, 28 February 2014

How to Connect MySql,Select Database,Execute query

<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";


//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>


<?php
//select a database to work with
$selected = mysql_select_db("examples",$dbhandle)
or die("Could not select examples");
?>




<?php
//execute the SQL query and return records
$result = mysql_query("SELECT id, model, year FROM cars");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
echo "ID:".$row{'id'}." Name:".$row{'model'}."
".$row{'year'}."<br>";
}
?>


Here is the full code.....
<?php
$username = "your_name";
$password = "your_password";
$hostname = "localhost";


//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>


<?php
//select a database to work with
$selected = mysql_select_db("examples",$dbhandle)
or die("Could not select examples");
?>
<?php
//execute the SQL query and return records
$result = mysql_query("SELECT id, model, year FROM cars");
//fetch tha data from the database
while ($row = mysql_fetch_array($result)) {
echo "ID:".$row{'id'}." Name:".$row{'model'}."
".$row{'year'}."<br>";
}
?>

No comments:

Post a Comment

Magento: How to get last order id

There are many ways to get last order id:   1. From checkout session: $lastOrderId = Mage::getSingleton('checkout/session'...