PHP MySql connectivity
First you need to verify that your hosting partner support php and mysql.
The easiest way to check this is create a php file with below code block.
<?
phpinfo();
?>
After upload this php , you can call this php and see what are the modules that are installed in your server.
Sample code
<?
$link = mysql_connect(’localhost’, ‘database_name’, ‘password’);
if (!$link) {
die(’Could not connect: ‘ . mysql_error());
}
//echo ‘Connected successfully’;
mysql_select_db(”database_name”) or die(mysql_error());
// Get all the data from the “example” table
?>
Execute query
<?
$result = mysql_query(”SELECT `product`.`SubId`
FROM `product` “)
or die(mysql_error());
?>
Print results
<?
while($row = mysql_fetch_array( $result )) {
echo $row['SubId'];
}
?>
Remember to close the database connection at the end..
<?
mysql_close($link);
?>
This is a simple php code to retrieve data from a Mysql table. To print records you have to have data in the table.
You can insert data using below SQL.
mysql> insert into tablename(col1,col2) values (’aaa’,'bbb’);















Leave a reply
Spam protection by WP Captcha-Free