The data collected by myself is ACCESS, but my program is mysql, so I wrote a program, and the program went three steps. I would like to share with my friends who like to operate the database. 1. connect to mysql with the following code: $ dbhostquot; l... the data collected by myself is ACCESS, but my program is mysql, so I wrote a program, and the program went three steps. I would like to share with my friends who like to operate the database.
1. connect to mysql with the following code:
$ Dbhost = "localhost: 3307"; // server $ db = "dataname"; // Database $ dbuser = "root "; // username $ dbpass = "********"; // password $ db_qianzhui = "sdb _"; // table prefix $ link = mysql_connect ($ dbhost, $ dbuser, $ dbpass); if (! $ Link) echo "link failed! "; Else echo" successful !!! "; Mysql_query (" set names 'utf8' "); mysql_query (" set character set UTF8 "); // >>> solve the problem of mysql_query ("SET CHARACTER_SET_RESULTS = utf8'"); // >>>> code mysql_select_db ("{$ db }");
2. connect to the access Database. the code is as follows:
$ Datapath = "data. mdb "; $ fenlei =" 101 "; $ conn = new com (" ADODB. connection "); $ connstr =" DRIVER = {Microsoft Access Driver (*. mdb)}; DBQ = ". realpath ($ datapath); // Open source code phprm.com $ conn-> Open ($ connstr); $ rs = new com ("ADODB. recordSet "); $ rs-> Open (" select * from information where lanmu3id = 13 ", $ conn, 1, 1); // query *. in the MDB file
3. read and write operations as follows:
While (! $ Rs-> eof) {// $ f = $ rs-> Fields (1); // 1. assign values (* for debugging) // echo $ f-> value; // 2. check whether the code can be written (* for debugging). // assign values to the variables respectively. here, 'gb2312' and 'utf-8' are used to solve the garbled problem! $ Id = iconv ('gb2312', 'utf-8', $ rs-> Fields (ID)-> value); // ID is the access field, or use a number to represent $ name = iconv ('gb2312', 'utf-8', $ rs-> Fields (title)-> value ); $ jianjie = iconv ('gb2312', 'utf-8', $ rs-> Fields (1)-> value); $ content = iconv ('gb2312 ', 'utf-8', $ rs-> Fields (content)-> value); $ down = iconv ('gb2312', 'utf-8 ', $ rs-> Fields (download)-> value); echo "". $ name. "already inserted
"; // Output the insert record. // execute INSERT in sequence. The value is the variable $ SQL =" insert INTO 'shopex '. 'SDB _ article' ('article _ id', 'node _ id', 'title', 'content', 'uptime', 'ifpub', 'align ', 'filetype', 'filename', 'orderlist', 'disabled ') VALUES ('',' {$ fenlei} ',' {$ name }', '{$ info}', '123', '1', Null, Null, NULL, NULL, 'false ')"; //// the above is the SQL statement inserted into the MYSQL database //// mysql_query ($ SQL); // execute the statement !!! /// Echo $ rs-> Fields (name)-> value ."
"; $ Rs-> MoveNext (); /// an individual is used to convert a database from ACCESS to mysql ,}
Article URL:
Reprint ^ at will, but please attach the tutorial address.