Can I use multiple query codes?

Source: Internet
Author: User
Can I use multiple query codes? $ bliang = 'this is A variable' $ SQL = SELECT & nbsp; * & nbsp; FROM & nbsp; table A & nbsp; WHERE & nbsp; cart & nbsp; LIKE & nbsp; '%. $ bliang. % '$ query = mysql_query ($ SQL); can I use multiple pieces of query code?


$ Bliang = 'This is a variable'
$ SQL = SELECT * FROM table A WHERE cart LIKE '%. $ bliang. %'
$ Query = mysql_query ($ SQL );
While ($ row = mysql_fetch_array ($ query )){
 
............
}


The above is the query code, and when I use it, I only need to use it like this, for example, $ row [$ bliang = 'category 2'] to classify the content under 2.

$ Row [$ bliang = 'Category 3'] displays the content under Category 3.

How can this requirement be achieved?

------ Solution --------------------
I just learned php, and I will give you a reference for my own classes. all database operations are here.

//
------ Solution --------------------
PHP version 5.3
// Database operation Order by phuai007
// Date 2014/2
Class my_ SQL {
Public $ dsn = 'MySQL: host = localhost; dbname = lif2 '; // host indicates the database connection address, and dbname indicates the database name.
Public $ user = 'root'; // database connection username
Public $ pass = '000000'; // password
Public $ names = 'set NAMES utf8'; // database query encoding
// Query the database return results
Public function SQL _select ($ SQL ){
Try {
$ Dbh = new PDO ($ this-> dsn, $ this-> user, $ this-> pass );
$ Dbh-> query ($ this-> names );
Return $ dbh-> query ($ SQL );
$ Dbh = null;
}
Catch (Exception $ e ){
Echo 'Error: '. $ e-> getMessage ();
}
}
// Operation (update/delete/insert) with no returned results
Public function SQL _one ($ SQL ){
Try {
$ Dbh = new PDO ($ this-> dsn, $ this-> user, $ this-> pass );
$ Dbh-> exec ($ this-> names );
$ Dbh-> exec ($ SQL );
$ Dbh = null;
}
Catch (Exception $ e ){
Echo 'Error: '. $ e-> getMessage ();
}
}
// Operate on multiple data records (update/delete) with no returned results
Public function SQL _more ($ SQL, $ str ){
Try {
$ Dbh = new PDO ($ this-> dsn, $ this-> user, $ this-> pass );
$ Dbh-> exec ($ this-> names );
Foreach ($ str as $ arrs ){
$ Dbh-> exec ($ SQL. $ arrs );
}
$ Dbh = null;
}
Catch (Exception $ e ){
Echo 'Error: '. $ e-> getMessage ();
}
}

// Results returned by the parameterized Query Database (single)
Public function cs_ SQL _select ($ SQL, $ str ){
Try {
$ Dbh = new PDO ($ this-> dsn, $ this-> user, $ this-> pass );
$ Dbh-> setAttribute (PDO: ATTR_EMULATE_PREPARES, false );
$ Dbh-> query ($ this-> names );
$ Stmt = $ dbh-> prepare ($ SQL );
$ Stmt-> bindValue (": key", $ str, PDO: PARAM_INT );
$ Stmt-> execute ();
Return $ stmt;
$ Dbh = null;
}
Catch (Exception $ e ){
Echo 'Error: '. $ e-> getMessage ();
}
}
// Parameters query multiple data records (delete/update) with no returned results
Public function cs_ SQL _more ($ SQL, $ str ){
Try {
$ Dbh = new PDO ($ this-> dsn, $ this-> user, $ this-> pass );
$ Dbh-> setAttribute (PDO: ATTR_EMULATE_PREPARES, false );
$ Dbh-> exec ($ this-> names );
Foreach ($ str as $ arrs ){
$ Stmt = $ dbh-> prepare ($ SQL );
$ Stmt-> bindValue (": key", $ arrs, PDO: PARAM_INT );
$ Stmt-> execute ();
}
$ Dbh = null;
}
Catch (Exception $ e ){
Echo 'Error: '. $ e-> getMessage ();
}
}
// Parameterized query operation (delete/update) with no returned results
Public function cs_ SQL _one ($ SQL, $ str ){
Try {
$ Dbh = new PDO ($ this-> dsn, $ this-> user, $ this-> pass );
$ Dbh-> setAttribute (PDO: ATTR_EMULATE_PREPARES, false );
$ Dbh-> exec ($ this-> names );
$ Stmt = $ dbh-> prepare ($ SQL );
$ Stmt-> bindValue (": key", $ str, PDO: PARAM_INT );
$ Stmt-> execute ();
$ Dbh = null;
}
Catch (Exception $ e ){
Echo 'Error: '. $ e-> getMessage ();
}
}


////////
}
?>

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.