Problems caused by a single instance when phpcmsdbfactory re-creates a link

Source: Internet
Author: User
Phpcms has always encountered bugs while using it. it cannot be completely blamed. phpcms mainly loads the class library and mysql has db setting options.

Phpcms has always encountered bugs while using it. it cannot be completely blamed. phpcms mainly loads the class library and mysql has db setting options.

 pc_base::load_sys_class("get_model", "model", 0);                                                $get_db = new get_model();                                                //var_dump($get_db);                                                $r = $get_db->sql_query("select * from v9_news where catid in ($catid) and status=99 and timetask!=0 order by id desc LIMIT 20");

Execution error db to other databases

Phpcms does not strictly set the database when the program loads multiple mysql instances.

Some less rigorous code libraries are loaded with mysql for execution.

Mysql_select_db ("test_db ");

But not reset

Phpcms/libs/classes/db_factory.class.php

/*** Get database operation instance * @ param $ db_name database configuration name */public function get_database ($ db_name) {if (! Isset ($ this-> db_list [$ db_name]) |! Is_object ($ this-> db_list [$ db_name]) {$ this-> db_list [$ db_name] = $ this-> connect ($ db_name );} return $ this-> db_list [$ db_name];}

In this way, the link may be invalid and the database will be incorrectly executed.

We recommend a php code to view the information of the currently used database.

$query="select database() AS `db`, user() AS `user`"; $result=mysql_query($query); $row = mysql_fetch_assoc($result); echo 'database: '.$row['db'],'

'; echo 'user: '.$row['user'];

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.