| |

VerySource

 Forgot password?
 Register
Search
View: 674|Reply: 1

Regarding the query of MYSQL data in PHP, wait online.

[Copy link]

2

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-23 19:40:01
| Show all posts |Read mode
I wrote a function.

// ************************************************ *
// Function name: Ado_Db
// Function: execute SQL statement
// Parameter: $ sql--SQL statement
// $ mors--first select master-slave library 0 as slave library, 1 as master library, default slave library
// ************************************************ *
function Ado_Db ($ sql, $ mors = 0)
{
if ($ mors == 0)
{
GetSlave (); // Open the slave library, only for reading data (select)
mysql_select_db (DATANAME);
    if (mysql_query ($ sql))
{
            $ result = mysql_query ($ sql);
            $ row = mysql_fetch_array ($ result);
return $ row;
        }
else
{
return FALSE;
}
}
else
{
GetMaster (); // Open the main library and write the library (DELETE, UPDATE, INSERT)
mysql_select_db (DATANAME);
    if (! mysql_query ($ sql))
{
     return FALSE;
}
}
Ranch

}
-------------------------------------------------- --------
$ row = Ado_Db ($ sql);

I want the function to first determine if the database has this record. If there is one, it returns an array to $ ROW. If there is no record, it returns a FALSE to $ row. Please help me to see how I can modify this custom function.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-8 21:00:01
| Show all posts
function Ado_Db ($ sql, $ mors = 0) {
   if ($ mors == 0) {
      GetSlave (); // Open the slave library, only for reading data (select)
      mysql_select_db (DATANAME);
      $ result = @mysql_query ($ sql) or return false;
      if (mysql_num_rows ($ result)) {
         $ row = mysql_fetch_array ($ result);
         return $ row;
      } else {
         return false;
   } else {
      GetMaster (); // Open the main library and write the library (DELETE, UPDATE, INSERT)
      mysql_select_db (DATANAME);
     @mysql_query ($ sql) or return flase;
   }
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list