HeatWare.net header image
HeatWare.net
TwitterRSSEmail
  • Home
  • Windows
    • Windows 8
    • Windows 7
    • Windows Vista
    • Windows XP
  • Linux/Unix
  • Mac
  • Mobile
    • Android
    • iOS
    • Phones (Help / Resources)
  • Software / Programming
    • Free Software
    • Programming – General
    • PHP
    • Ruby/Rails
    • Quality Assurance (QA)
    • Software – General
    • Software Help
    • Databases
  • Cool Websites
  • Other
    • Deals & Bargains
    • News
    • Video Games
    • Hardware
    • Electronics
  • About

2 comments / April 29, 2014 / guest / Databases, Programming – PHP

Useful tips for PHP developers using MySQL

MySQL is a very common database used while developing web application. When developers are using PHP as their main programming language, they prefer MySQL as database. We are going to discuss some of uncommon but useful queries and precautions every developer should follow and will be taken care of.

    1. Why not to use mysql_* functions in PHP:

Developers should not use mysql_* functions, such as: mysql_query(), mysql_fetch_assoc() and mysql_fetch_array(), as it does not support asynchronous queries, stored procedures, multiple statements, transactions and latest functionalities of MySQL. This function is officially deprecated by MySQL development and has lack of Object Oriented interface etc. There are two main alternatives can be used instead. One is PDO and another is use of mysqli_* functions. PDO stands for PHP data objects and is even better solution than using mysqli_*, just because its object oriented way to connect with database.

   2. When to use single quotes, double quotes and backticks:

Single quote should be used when dealing with string values such as when using INSERT query and VALUES(). Double quotes also work similar to single quote and for strings, but single quote is supported by other familiar and widely used RDBMS. It is good practice to use single quotes. On the other hand backticks are used for column and table name identifier. Backticks are only necessary when the identifier name is similar to MySQL reserved keywords or contains whitespace characters.

  3.  Use of REPLACE and INSERT IGNORE for duplicate entries:

If database contains a large number of entries and developer want to add more values in it and also to ignore duplicate entries then they should go with these queries. In REPLACE, if any record exists then it will be overwritten and if a new record does not then will be created. Do not use this query when you want to skip an already existing record. In INSERT IGNORE, if a data already exist then it will be skipped otherwise a new record will be inserted into database.

Example of REPLACE:

REPLACE INTO `table_name`
SET `column_name_1` = ‘value_1′,
`column_name_2` = ‘value_2’,
` column_name_3` = ‘value_3’;

Example of INSERT IGNORE:

INSERT IGNORE INTO `table_name`
SET `column_name_1` = ‘value_1′,
`column_name_2` = ‘value_2’,
` column_name_3` = ‘value_3’;

Related Posts

  • How to call JavaScript function from PHP
  • Create a compressed MySQL database dump/backup (Linux)
  • MySQL 5.6 - How to log slow queries (Linux)
  • Solved! Installing mysql gem - extconf.rb failed error
  • Fun & Useful Windows 8 Applications

mysql PHP

2 comments… add one
  1. Peter Siddle February 18, 2015, 12:36 am

    Great post! Thanks for sharing these helpful and effective tips of MySQL for PHP developers.

  2. Kirt December 11, 2015, 9:23 am

    Beginner with both PHP and MySQL. This was one of the easiest, most straightforward posts to understand a powerful function. I will be back to this site often. Thanks,

Cancel reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Why You Should Consider Diving Apps
  • How to Buy a Smartphone that Fits Your Budget
  • How to Overcome Frustrating PDF Stress
  • Convert PDF to Word: Easy, Reliable and Quality Conversion
  • PDF to Excel App ­ – A New Way of Handling Tricky Documents

Recent Comments

  • Valarie Walter on Basic Troubleshooting Steps for your Cell Phone
  • John Mists on A Brief History of Android OS
  • syarif on PostgreSQL: How to reload config settings without restarting database
  • Raghu on How to SSH to a server using Ruby – Part I
  • francisco clemente on Basic Troubleshooting Steps for your Cell Phone

Tags

ACSLS Android Bargain Cell Phones Cool Software Cool Websites Databases Deals Ebooks Facebook Free Software G2x Galaxy S5 iOS iPhone Kindle LG Linux Linux/Unix Mac Mobile mysql Office OpenStack OS X PHP Postgres PostgreSQL ruby Samsung Galaxy S6 Shell Smartphones Sun T-Mobile Tips Tips & Tricks Ubuntu Unix Virtualization VMWare Windows Windows 7 Windows 8 Windows Vista Windows XP

Latest Tweet

Follow @HeatwaredotNet

SP
@HeatwaredotNet

  • Why You Should Consider Diving Apps https://t.co/Is41cdUv2I #diving-apps
    about 6 years ago

All Categories

Other Links

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2015 — HeatWare