In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "how to connect php7 to use dm database". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to connect php7 to use dm database" can help you solve the problem.
Preface
The extension of php_dm is mainly used here, and I didn't do much research because there is too little information about pdo_dm.
There are two things to remind you when instantiating a database. Character sets and strings are case-sensitive. Remember to set them up in advance and don't dig holes for yourself.
My experience is that the data table names and field names migrated by mysql are all lowercase, resulting in later use of various pits, and later found that case sensitivity can be removed.
Here, use the CITY table in the official sample library to demonstrate the various ways to use php7.2.
Query
Don't talk too much nonsense, put the code first
/ / Connect to the database $link = dm_connect ("localhost", "SYSDBA", "SYSDBA"); if (! $link) {var_dump (@ dm_error ()); var_dump (iconv ("GBK", "UTF-8", @ dm_errormsg ());} dm_setoption ($link,1,12345,1); / / set the relevant properties of dm connections and statements, set UTF8 $query = "select * from DMHR.CITY"; $result = dm_exec ($link,$query) Print "query result:"; while ($line = dm_fetch_array ($result)) {print_r ($line); echo'
';} / * release resources * / dm_free_result ($result); / * disconnect * / dm_close ($link)
There is a great difference between the use of php5 and php7, the official extension of php for Dameng. Many methods in php5 cannot be used in php7, and some methods are replaced by other methods in php7. Most of the materials on the Internet are php5, which can not be used in php7 at all.
Query sentence out of the Chinese garbled problem is a sinkhole, checked for a long time to try this method, there are other more elegant methods are also welcome to teach me, we learn from each other.
Insert / / connect to the database $link = dm_connect ("localhost", "SYSDBA", "SYSDBA"); if (! $link) {var_dump (@ dm_error ()); var_dump (iconv ("GBK", "UTF-8", @ dm_errormsg ());} dm_setoption ($link,1,12345,1) / / set properties related to dm connections and statements, set UTF8 $query = "INSERT INTO DMHR.CITY (CITY_ID,CITY_NAME,REGION_ID) VALUES ('JL',' Jilin','1')"; $result = dm_exec ($link,$query); if ($result) {echo "insert successfully"; / / Curve query insert id / * $query = "SELECT @ @ IDENTITY as insert_id"; $result = dm_exec ($link,$query) $line = dm_fetch_array ($result); echo', ID:'; print_r ($line); * /} / * release resources * / dm_free_result ($result); / * disconnect * / dm_close ($link)
The official dm_insert_id () function seems to be available only with php5. Php7 does not have this function and can only query the self-increasing id value through the curve. Of course, the table demonstrated does not have self-increasing ID, and the sentence SELECT @ @ IDENTITY as insert_id is bound to query success. Even if the insertion fails, it will return the self-incrementing ID of the previous successful insertion. Do not use self-incrementing ID to determine whether the statement is inserted successfully.
Update / / connect to the database $link = dm_connect ("localhost", "SYSDBA", "SYSDBA"); if (! $link) {var_dump (@ dm_error ()); var_dump (iconv ("GBK", "UTF-8", @ dm_errormsg ());} dm_setoption ($link,1,12345,1); / / set the relevant properties of dm connections and statements, and set UTF8 $query = "UPDATE DMHR.CITY SET REGION_ID='2' WHERE CITY_ID='JL'" $result = dm_exec ($link,$query); if ($result) {echo "updated successfully";} / * release resources * / dm_free_result ($result); / * disconnect * / dm_close ($link)
The update is simple.
Delete / / connect to the database $link = dm_connect ("localhost", "SYSDBA", "SYSDBA"); if (! $link) {var_dump (@ dm_error ()); var_dump (iconv ("GBK", "UTF-8", @ dm_errormsg ());} dm_setoption ($link,1,12345,1); / / set the relevant properties of dm connections and statements, and set UTF8 $query = "DELETE FROM DMHR.CITY WHERE (CITY_ID='JL')" $result = dm_exec ($link,$query); if ($result) {echo "deleted successfully";} / * release resources * / dm_free_result ($result); / * disconnect * / dm_close ($link)
Deletion is also very simple, there is no special attention.
Business
According to the official document, "DM does not provide a statement that explicitly defines the beginning of the transaction, and the first executable SQL statement (except the login statement) implies the start of the transaction." this is the reason why there is no defined method for starting a transaction, but when we want to start a transaction from a certain program, we can use the dm_autocommit () function to turn off the automatic commit of the transaction and open it after the end of the program.
/ / Connect to the database $link = dm_connect ("localhost", "SYSDBA", "SYSDBA"); if (! $link) {var_dump (@ dm_error ()); var_dump (iconv ("GBK", "UTF-8", @ dm_errormsg ());} dm_setoption ($link,1,12345,1) / / set properties related to dm connections and statements, set UTF8 $query = "INSERT INTO DMHR.CITY (CITY_ID,CITY_NAME,REGION_ID) VALUES ('JL',' Jilin','1')"; $result = dm_exec ($link,$query); if ($result) {echo "inserted successfully." ;} $result = dm_autocommit ($link,false); / / transaction auto-commit off $query = "UPDATE DMHR.CITY SET CITY_NAME=' Liaoning 'WHERE (CITY_ID='SY')"; $result = dm_exec ($link,$query); if ($result) {echo "updated successfully, rollback." ;} dm_rollback ($link); / / rollback / / dm_commit ($link); / / commit $result = dm_autocommit ($link,true); / / enable transaction autocommit, end transaction / * disconnect * / dm_close ($link); stepped hole
First, get the time in the timestamp format in the database
Select DATEDIFF (s, '1970-01-01 00, GETUTCDATE ())
2. If the database used before is mysql, note that the time precision will be longer if it is not 0, the time format DATETIME and TIMESTAMP should be followed by the scale.
3. Some fields will be capitalized if queried, such as "count"
Solution: quote the field in double quotation marks. Example:
Select count (1) as "count" from "DMHR". CITY "
Fourth, the use of group by statements is very strict (or mysql's group by is too relaxed), all fields except aggregate functions in select must be in group by.
Bifang gives an example of a mistake:
Select EMPLOYEE_NAME,JOB_ID from "DMHR". "EMPLOYEE" group by JOB_ID
EMPLOYEE_NAME and field are not in group by, execution must fail
Provide a solution:
Select * from "DMHR". "EMPLOYEE" where EMPLOYEE_ID in (select min (EMPLOYEE_ID) as minid from "DMHR". "EMPLOYEE" group by JOB_ID)
Similarly, if there are fields other than the aggregate function in the select, you need to add group by. Examples of errors:
Select min (EMPLOYEE_ID), EMPLOYEE_NAME,JOB_ID from "DMHR". "EMPLOYEE"
There are other fields in select besides the min () function, and execution is bound to fail.
If you have to add aggregate functions to many other fields, provide an idea:
Select t1.EMPLOYEE NAME group by JOB_ID t1.JOBYEENAME DMHR from t2.minid from "DMHR". "EMPLOYEE" t1left join (select min (EMPLOYEE_ID) as minid,JOB_ID from "DMHR". "EMPLOYEE" group by JOB_ID) T2 on t2.JOB_ID=t1.JOB_IDwhere t1.EMPLOYEE_ID in (select min (EMPLOYEE_ID) as minid from "DMHR". "EMPLOYEE" group by JOB_ID); this is the end of the introduction on "how php7 connects to the dm database". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.