Php + mysql for convenient query

Source: Internet
Author: User
Tags mysql query
Document directory
  • B-Clone Database Table with all data

MySQL is a programming language based on C and C ++ later than mySQL 1995. ITA is the most commonly used open source database today, because of the great verstality applied online. MySQL is claimed  more than 65,000 downloads every day. It is also the best choice for the next generation OFA and PHP/Perl/Python. Millions of websites and one company's websites, such as Google, Alcatel-Lucent and Zappos, depend on MySQL. It runs on Mac OS, Linux and Solaris of almost all major platformâ.

MySQL is favored by many database developers, DBAs, and IT managers. The reason is that databases with high performance, high cost effectiveness, and easy to use. Whether you are new users or experienced developers, you will like it because of its wide range of development tools,  training  and support services, mySQL is a key factor for any successful development.

 

1-clone and use MySQL to query databases or tables.
CREATE TABLE newTableNameLIKE oldTableName
B-Clone Database Table with all data

In case you need to clone the whole tableAlong with the data, Below methods can help you.

1 CREATE TABLE newTableName2 SELECT *3 FROM oldTableName

The same can be achieved with the help of two queries like below:

CREATE TABLE newTableNameLIKE oldTableName;INSERT INTO newTableNameSELECT *FROM oldTableName;

 

 

 

2-return a variable from MySQL Query

PHP is the world's leading language. Today's ISA is the best choice for MySQL databases. We can do some smart functions to reduce our work. Â this query is technically proficient and will help you get a variable value and use a simple PHP function.

1 function quickVarGet($myquery){2 $execQuery = mysql_query($myquery);3 $myRow = mysql_fetch_array($execQuery);4 mysql_free_result($execQuery );5 $output = $myRow[0];6 return $output;7 }

 

Therefore, you have to re-do it. Use the following command to return a variable anywhere.

1
$email = quickVarGet("SELECT email from users where id = 1");

 

 

The preceding query will return a unique email address, and the output may be "€20.admin @ smashinghub.com â € considering a record in the database.

3-last input ID of MySQL

Sometimes, we need to obtain the ID of the last query. To implement this function, the following things can help you.

// Ensure that the database connection getTheLastID = mysql_insert_id (); echo $ getTheLastID;
4-Enable your script to inject proof to MySQL

Websites are mostly saved these days, but are still a lot of new developed don't disturb, making their script injection proofs. The following simple PHP functions will make it impossible for the syringe to intrude into your database.

1
Mysql_real_escape_string (TRIM ($ VAR ));

This allows you to create some functions more skillfully so that they are easier to use in different locations.

123456789
Function protection ($ VAR) {$ VAR = mysql_real_escape_string (decoration of $ var); returns $ VAR ;}

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.