Tuesday, July 8, 2014

PHP CRUD operation on BlueMix

When you want do to an application to initialize the database (including create table and date),I think use PHP is a quick solution to do that.I was trying to find this kind of sample,fortunate I find one in jazzHub,so you can follow it to do your mysql solution on BlueMix.

The project  url is at https://hub.jazz.net/project/andrewhujazz/PHPMySQLProject/overview.You can apply a jazzhub account to fork his application to deploy on the BlueMix,or use git clone command to clone the project on your local side.The git url is https://hub.jazz.net/git/andrewhujazz/PHPMySQLProject.

The detail function you can see below screenshot,it provide create table,insert table,drop table,

When you write code you need to notice ,when you open the mysql connection,you also need to provide port,since the port might be not default port..I list some code for your reference.

<div id="content2">
<h2>MySQL Service</h2><hr>
<b>MySQL Information</b>
<hr>
<?php
$services = getenv("VCAP_SERVICES");
$services_json = json_decode($services,true);
$mysql_config = $services_json["mysql-5.5"][0]["credentials"];
$db = $mysql_config["name"];
$host = $mysql_config["host"];
$port = $mysql_config["port"];
$username = $mysql_config["user"];
$password = $mysql_config["password"];
if ($host=="") {
echo "<b> There is no mysql service.</b><br>";
} else {
?>
MySQL DB Name : <?php echo $db ?> <br>
MySQL Host : <?php echo $host ?> <br>
MySQL Port : <?php echo $port ?> <br>
MySQL username : <?php echo $username ?> <br>
MySQL password : <?php echo "********" ?><br>
<hr>
<b> Create Table</b><br>
<?php
$conn = mysql_connect($host . ':' . $port, $username, $password);
if(! $conn ) {
 echo('Could not connect: ' . mysql_error());
}
mysql_select_db($db);
 if ($cmd=="create") {
$sql_create = 'CREATE TABLE SAMPLE (name CHAR(30), comment CHAR(255), time DATETIME)';
$retval = mysql_query($sql_create, $conn );
if(! $retval ) {
 echo('Could not create database table: ' . mysql_error() . '<br/>');
} else {
    echo "<script>alert('Created database table successfully')</script><script>window.location='mysql.php'</script>";
    }
 } ?>
<a href="mysql.php?cmd=create">[Create] </a>
<hr>
<b> Insert Data</b><br>
<?php
$sql_read = 'SELECT * FROM SAMPLE ';
$retval = mysql_query($sql_read, $conn );
if(! $retval )
{
  echo('Could not read SAMPLE table: ' . mysql_error());
}
echo "<table><tr><td>name</td><td>comment</td><td>Date</td>";
while ($dbfield = mysql_fetch_assoc($retval)) {
    echo "<tr><td>".$dbfield['name'] . '</td>';
    echo "<td>".$dbfield['comment'] . '</td/>';
    echo "<td>".$dbfield['time'] . '</td></tr>';
}
echo "</table>";
?>

<?php
if ($cmd=="insert") {
$sql_insert = 'INSERT INTO SAMPLE (name, comment, time) VALUES ( "name",   "comment", NOW() )';
$retval = mysql_query($sql_insert, $conn );
if(! $retval ) {
 echo('Could not enter data: ' . mysql_error() . '<br/>');
} else {
    echo "Entered data successfully<br/><script>window.location='mysql.php'</script>";
    }
 } ?>
<a href="mysql.php?cmd=insert">[Insert] </a>
<hr>
<b> Drop Table</b><br>
<?php
 if ($cmd=="drop") {
$sql_drop = 'DROP TABLE SAMPLE';
$retval = mysql_query($sql_drop, $conn );
if(! $retval ) {
 echo('Could not drop database table: ' . mysql_error() . '<br/>');
} else {
    echo "<script>alert('Dropped database table successfully')</script><script>window.location='mysql.php'</script>";
    }
 } ?>
<a href="mysql.php?cmd=drop">[Drop] </a>
<?php }?>
</div>

Also when you deploy your php application,you had better provide a manifest.yml,it describe the deployment info on the BlueMix.See below sample manifest.yml

---
applications:
- name: myphpsample
  memory: 128M 
  instances: 1
  host: myphpsample
  domain: ng.mybluemix.net
  buildpack: https://github.com/dmikusa-pivotal/cf-php-build-pack.git
  path: .

After deployment,you need to bind your php application on existing my sql service.

61 comments:

  1. Great Post, Actually PHP is a beautiful source for developing a database driven web application, I love this post, thanks for spending your time for discussing about this topic.
    Regards,
    PHP Training in Chennai|PHP Course in Chennai

    ReplyDelete
  2. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me
    best rpa training in chennai
    rpa training in chennai |
    rpa online training
    rpa course in bangalore
    rpa training in pune
    rpa training in marathahalli
    rpa training in btm

    ReplyDelete
  3. This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me
    best rpa training in chennai
    rpa training in chennai |
    rpa online training
    rpa course in bangalore
    rpa training in pune
    rpa training in marathahalli
    rpa training in btm

    ReplyDelete
  4. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
    python course in pune | python course in chennai | python course in Bangalore

    ReplyDelete
  5. Thanks you for sharing this unique useful information content with us...
    Informatica Bangalore

    ReplyDelete
  6. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.

    data analytics courses

    data science interview questions

    business analytics courses

    data science course in mumbai

    ReplyDelete
  7. Thanks for sharing such knowledgeable information on AWS. Looking forward to see more of such informative posts.
    AWS Training In Hyderabad

    ReplyDelete
  8. I like viewing websites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!

    Correlation vs Covariance

    ReplyDelete
  9. I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful.

    artificial intelligence course

    ReplyDelete
  10. I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.

    ReplyDelete
  11. I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community. data science courses

    ReplyDelete
  12. Glad to chat your blog,I seem to be forward to more reliable articles and i think we all wish to thank so many good articles,blog to share with us.data scientist courses

    ReplyDelete
  13. You can take pride in the way you write such brilliant articles. It is reflected in the pattern of writing when a writer does the required homework to write quality material. Thank you so much for sharing this magnificent content.
    SAP training in Mumbai
    SAP course in Mumbai

    ReplyDelete
  14. I have truthfully never come across such overwhelmingly good piece of content. I agree with your valid points and your ideas. This piece of information is really great.
    Thank you so much.
    SAP training in Kolkata
    SAP course in kolkata

    ReplyDelete
  15. Your site is genuinely cool and this is an unprecedented moving article and If it's not all that much difficulty share more that way. Much thanks to you…

    AI Training in Hyderabad

    ReplyDelete
  16. Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best.
    data analytics course in hyderabad

    ReplyDelete
  17. This post is incredibly helpful for those looking to perform CRUD operations with PHP on BlueMix. The detailed code examples, explanations, and provided links make it a valuable resource for developers. Thank you for sharing this insightful guide!
    Data Analytics Courses in Nashik

    ReplyDelete
  18. Hello Blogger,
    This article provides a clear and detailed guide on using PHP for CRUD operations on BlueMix, making it easier for developers to work with MySQL databases in the cloud. Good job.
    Data Analytics Courses In Dubai

    ReplyDelete
  19. Hey! Very interesting blog, and post is a valuable addition to the resources available for developers looking to leverage BlueMix for their projects! Thank you!
    Data Analytics Courses In Chennai

    ReplyDelete
  20. The use of PHP for CRUD operations on BlueMix is explained in precise detail in this article, making it simpler for developers to interact with MySQL databases in the cloud. Well done.
    Data Analytics Courses in Agra

    ReplyDelete
  21. This blog could be a game-changer for those looking to master the basics of Create, Read, Update, and Delete operations in PHP on the BlueMix platform.
    Digital marketing courses in illinois

    ReplyDelete
  22. Thanks for sharing valuable and insightful blog on PHP CRUD operation on BlueMix.
    Digital Marketing Courses in Italy

    ReplyDelete
  23. I found the blog post on PHP CRUD operation on BlueMix very interesting and informative.
    data analyst courses in limerick

    ReplyDelete
  24. Thank you for sharing knowledgeable post on PHP CRUD operation on BlueMix.
    Investment banking training Programs

    ReplyDelete
  25. The content of your blog is precise and straightforward, which makes it easy to understand.
    Data analytics framework

    ReplyDelete
  26. Performing PHP CRUD operations on IBM BlueMix (now IBM Cloud) involves creating a PHP application that connects to a database service. Utilize frameworks like Laravel or CodeIgniter for structured development, enabling Create, Read, Update, and Delete functionalities with RESTful APIs, ensuring seamless data management in cloud environments.
    Data science courses in Gurgaon

    ReplyDelete
  27. This article is an absolute gem! The information is broken down in such a clear and easy-to-understand way. I’m sure many people will find it extremely useful, just like I did. Thanks for putting together such an insightful piece.
    Data Analytics Courses in Delhi

    ReplyDelete
  28. Great job on outlining PHP CRUD operations on BlueMix! Your detailed guidance makes it accessible for developers looking to master this essential skill. Keep sharing your insights—you're making a real difference in the coding community!
    Data Science Courses in Singapore

    ReplyDelete
  29. What an exceptional blog! Your passion and expertise are evident in every post. I appreciate how you make complex topics accessible—thank you!

    Data science courses in Gujarat

    ReplyDelete
  30. This article provides a comprehensive guide for setting up a PHP CRUD operation on BlueMix, including clear code snippets for MySQL table creation, data insertion, and table deletion. It's a valuable resource for developers looking to quickly deploy PHP applications on the BlueMix platform using MySQL services.

    For those seeking to enhance their technical skills, data analytics courses in Ghana by IIM Skills offer excellent training programs to help professionals work with data effectively, making database management and deployment even more powerful. Data Analytics Courses in Ghana

    ReplyDelete
  31. This blog provides a clear and practical guide for performing CRUD operations using PHP on BlueMix with a MySQL database. It offers useful insights, including code snippets, to help set up the database connection, create tables, insert data, and drop tables. The author highlights important details like handling non-default MySQL ports and includes a well-structured example of a manifest.yml file for deployment. Overall, the blog is informative, easy to follow, and a great resource for anyone looking to implement PHP and MySQL on BlueMix effectively.
    data analytics courses in dubai

    ReplyDelete
  32. Your PHP CRUD operation tutorial on BlueMix is a fantastic resource for developers looking to streamline their projects. Clear and concise, it's exactly what beginners and pros alike need to get started. Keep sharing these practical guides—your readers will appreciate it!
    Data Science Courses in Singapore

    ReplyDelete
  33. "Thanks for the clear tutorial on PHP CRUD operations on Bluemix! The examples make it easy to follow along
    Data science courses in Bhutan

    ReplyDelete
  34. "Great tutorial on PHP CRUD operations on Bluemix! The step-by-step approach makes it easy to follow, even for beginners. This is a valuable resource for anyone looking to implement these operations in their projects!"

    data analytics courses in dubai

    ReplyDelete
  35. Great read! Your insights sparked my curiosity and encouraged me to think critically about the topic. I especially liked your examples—they really illustrated your points well. Thanks for sharing
    Online Data Science Course

    ReplyDelete
  36. I appreciate the tips you included for troubleshooting. Thanks for sharing your expertise!
    Data science courses in Bhutan

    ReplyDelete
  37. Great content on PHP. Very well written and informative.
    Data Science Courses in Hauz Khas

    ReplyDelete
  38. Thanks for sharing this insightful article! The step-by-step guide to setting up PHP with MySQL on BlueMix is really helpful, especially for those of us looking to streamline our database initialization processes. I appreciate how you highlighted the importance of specifying the port when opening the MySQL connection—it’s a detail that can easily be overlooked.
    Data science courses in Mysore

    ReplyDelete

  39. Here’s a five-line comment for your blog post:

    "I came across the Data Science Course in Dadar, and it looks fantastic!
    The curriculum covers essential topics that are crucial for budding data scientists.
    I’m particularly excited about the hands-on projects mentioned.
    It's great to see such opportunities available locally!
    I’m definitely considering enrolling after reading this."

    ReplyDelete
  40. "I took IIM Skills’ Data science while living in Mumbai, and it has been fantastic. The online format fits seamlessly into my schedule."

    ReplyDelete
  41. The post on Bluemix Tips about performing CRUD operations in PHP on Bluemix is very informative! It provides clear, step-by-step guidance on setting up and managing database interactions, making it accessible for developers at all levels. The practical examples and insights into best practices are particularly useful for anyone looking to work with PHP in a cloud environment. Thanks for sharing such valuable information!

    Data science courses in Bangalore.

    ReplyDelete
  42. This article is a great resource for anyone looking to set up a PHP CRUD operation on BlueMix! I appreciate the detailed explanation of the MySQL connection setup and the clear code snippets. Data science courses in Mysore

    ReplyDelete
  43. very informative and valuable content that you will provided thank you for sharing.
    Data science course in Bangalore

    ReplyDelete
  44. Great blog! I really appreciated the clear and concise explanation of setting up PHP CRUD operations on Bluemix. The step-by-step guide makes it easy to follow along, even for beginners. Thanks for sharing such helpful tips.

    Data science course in Gurgaon

    ReplyDelete
  45. Thank you for this insightful guide on performing PHP CRUD operations on Bluemix! Your step-by-step approach simplifies the process and makes it highly practical for developers working with cloud-based applications.
    Data science course in Lucknow

    ReplyDelete
  46. I appreciate how you’ve made PHP CRUD operation on BlueMix seem so easy. Your tips are practical and informative.
    Data Science Courses in China



    ReplyDelete
  47. A practical guide for developers to perform PHP CRUD operations on Bluemix. Great for beginners exploring cloud-based app development!
    Data science course in Gurgaon

    ReplyDelete
  48. You did an amazing job explaining a complicated topic. I feel like I have a much better understanding after reading this
    Data science courses in Bangalore

    ReplyDelete
  49. Thanks for sharing such knowledgeable information on AWS. Looking forward to see more of such informative posts.
    Data Science Course in Kolkata

    ReplyDelete
  50. Great explanation of the PHP CRUD operations on BlueMix! The step-by-step guide is very clear and helpful for beginners.
    Data science course in Bangalore

    ReplyDelete