current position:Home>How to rewrite the code of linking MySQL database?
How to rewrite the code of linking MySQL database?
2022-02-04 17:25:06 【CSDN Q & A】
// SQL server connection information$sql_details = array( 'user' => 'root', 'pass' => 'root', 'db' => 'table_demo', 'host' => 'localhost');
static function sql_connect ( $sql_details ) { try { $db = @new PDO( "mysql:host={$sql_details['host']};dbname={$sql_details['db']}", $sql_details['user'], $sql_details['pass'], array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ) ); } catch (PDOException $e) { self::fatal( "An error occurred while connecting to the database. ". "The error reported by the server was: ".$e->getMessage() ); } return $db; }
The above link SQL server Code of the database , How to write a link mysql What about the database ?
Take the answer :
static function sql_connect ( $sql_details ) { try { $db = @new PDO("mysql:host=".$sql_details['host'].";port=".$sql_details['port'].";dbname=".$sql_details['db'].";charset=".$sql_details['charSet'];, $sql_details['user'],$sql_details['pass'],array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION )); } catch (PDOException $e) { self::fatal( "An error occurred while connecting to the database. ". "The error reported by the server was: ".$e->getMessage() ); } return $db; }
$sql_details = array( 'user' => 'root', 'pass' => 'root', 'db' => 'table_demo', 'host' => 'localhost', 'port' => 3306, 'charSet' => 'utf8' );
Have a try. , Make sure it's turned on PDO Link way , Is to php.ini In profile Write off extension=php_pdo_mysql.dll The semicolon in front , And restart the service
Other answers 2:
This is just a variable , Access the corresponding database link information , Change it to you mysql Corresponding username、password、database and host Just fine .
Other answers 3:
PDO An abstraction layer that provides access to data , No matter which database you use , You can use the same function ( Method ) To query and retrieve data . So change it MySQL Connection information for the server ( Database user name 、 password 、 port 、 Database name 、 The server IP Address ) That's all right. .
copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041725036035.html
The sidebar is recommended
- QT how to read the network folder of the system
- ArrayList user-defined storage of student objects (name, age), plus an additional class, why is the class output null
- Can you show me how to do this
- How do I change this problem
- Android third-party library analysis, the latest Tencent Android experience in 2021
- How to download the processing drawing plug-in shape sketch
- Netty based on Http protocol server portal development, from a to Z, are the essence
- The reason why the MFC dialog box system menu close button cannot close the dialog box
- Netty source code analysis series (7) byte buffer bytebuf, java basic combat project aircraft war
- NB! This is the perfect JVM perfect notes, thoroughly understand and easily handle the interview. The fourth edition of Linux tutorial answers Meng Qingchang
guess what you like
-
This display box always appears when envi is opened
-
Find a dflux pulse heat source subroutine, which can change alternately?
-
C + + expression for addition, subtraction, multiplication and division
-
This is the solution in C + +
-
Unresolved external commands and symbols
-
Two submit buttons call the judgment of the same onclick event
-
Wechat payment docking. When the front-end calls up payment, the callback function returns the payment result. Why does the wechat official server send me a separate request to inform me of the payment result?
-
How does Vue project send the same post request to the background when any page is loaded
-
Freshmen, solve this problem. The middle grammar is simpler. We just learned a little
-
In a cycle, I put a group of intervals, and the number I want in the interval is output. How to output only a no when there is no number I want in the interval
Random recommended
- ACM basic question output is OK. The website submission is wrong. Please point out the problem
- What is the serverless application engine (SAE) experience?
- What is the data preparation for moving Hadoop data to maxcompute?
- What does project protection support?
- What are the three characteristics of serverless application engine (SAE)?
- What are the steps to prepare the maxcompute target table?
- What is SAE's efficient closed-loop Devops system?
- What if the application development service call fails in serverless?
- What is the permission relationship between maxcompute and dataworks?
- What are the three deployment modes currently supported by SAE?
- What are the operations of dataworks user management?
- What should I pay attention to in the configuration code of task configuration in ECs machine deployment?
- What does SAE application release three board axe include?
- What is the empowerment operation of dataworks user management?
- What is the fallback operation of dataworks user management?
- What is SAE omni-directional observability?
- What are the operations managed by maxcompute users?
- What is the role of metrics?
- What is the authorization operation of maxcompute user management?
- What is the function of logging?
- What is maxcompute role management?
- What is the function of tracing?
- What are the empowerment operations managed by maxcompute role?
- What does the Hadoop cluster environment include?
- What is the fallback operation managed by maxcompute role?
- What is the function of Java retmote debug?
- What is dataworks role management?
- What are other SAE diagnostic tool connection instances?
- What is the empowerment operation of dataworks role management?
- What is the authorization management of ACL (object operation)?
- What is the applicable scenario of SAE end cloud joint commissioning?
- What is the authorization operation of ACL (object operation) authorization management?
- What is the role of the cloud toolkit plug-in?
- What does it mean to use a data map as a data management tool?
- How does Devops drive new forms?
- What are the facts of OPS work?
- How to set to prohibit the download of the select results of dataworks to the local?
- How to set environment variables in serverless creation application?
- From the perspective of enterprises, what are the four typical enterprise computing power demand models?
- How to set the IP white list for accessing project?
- How to reasonably set the label of the field?