In php, how to export the database table to json/word/xml/excel

Database information export: word, excel, json, xml, sql Database recovery: from sql, from file ​ Specific usage: ​ First create a new test database mytest, and then create a table in it ​ PHP code: ​ ​ ​ Here is the code snippet: — — Table structure `test` — CREATE TABLE `test` ( `id` int(11) NOT NULL auto_increment, `name` varchar(100) NOT NULL, `email` varchar(200) NOT NULL, `age` int(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3; — –Export the data in the table `test` — INSERT INTO `test` (`id`, `name`, `email`, `age`) VALUES (1, 'pjq518', [email=]'[email protected]'[/email], 22), (2, 'xiaoyu', [email=]'[email protected]'[/email], 21); ​ ​ 1. Export json that can be easily called by ext ​ PHP code: ​ ​ ​ Here is the code snippet: $db=new db(); echo $db->toExtJson('test'); ​ //The output result is //{'totalCount':'2','rows':[{'id':'1', 'name':'pjq518','email':'[email protected]','age':& #39;22'},{'id':'2','name':'xiaoyu',' email':'[email protected]','age':'21'}]} ​ toExtJson($table, $start=”0″, $limit=”10″, $cOns=””) has 4 parameters, $table is the table name, $cons is the condition, which can be string or array ​ ​ 2. Export xml ​ PHP code: ​ ​ ​ Here is the code snippet: $db=new db(); echo $db->toExtXml('test'); ​ ​ //Output results ​ ​ 3. Export excel and word ​ PHP code: ​ ​ ​ Here…

In PHP, why does </script> not generate syntax parsing errors?

As a mainstream website construction language, PHP has many pitfalls during use, which requires programmers to think. ​ In a PHP script, if you write the following code ​ This php script did not prompt any errors, but directly output “?>”. It feels incredible, so we write the following code ​ This time it prompts a parsing error, Parse error: syntax error, unexpected '<' in … ​ Why doesn't an error appear the first time? ​ At this time we need to read the relevant manuals of PHP carefully. There are various ways of starting a block of PHP code: ​ There are four different pairs of opening and closing tags that can be used in PHP. Two of them, and are always available. The other two are short tags and ASP style tags, which can be turned on or off in the php.ini configuration file. Although some people find short tags and ASP-style tags convenient, they are less portable and generally not recommended. ​ That is to say, there are 4 tags in php, and (ASP style tag, abandoned in version 5.3.0)

In PHP, subclasses override parent class methods [parent::method name]_php example

In PHP, functions with the same name cannot be defined, and methods with the same name cannot be defined in the same class, so there is no method overloading. Methods with the same name as those of the parent class can be defined in the subclass alone, because the methods of the parent class already exist in the subclass, so the methods inherited from the parent class can be overridden in the subclass. The method of overriding the parent class in a subclass is to overwrite the methods inherited from the parent class in the subclass. Can’t the methods in the parent class be used directly if they are inherited by the subclass? Why do we need to overload it? Because there are some situations that we have to cover. For example, there is a “Bird” class, in which the general method “Fly” for birds is defined. Taking the “ostrich” class as its subclass will inherit the “flying” method, but as soon as the “flying” method in the “ostrich” class is called, the ostrich will fly away. Although ostriches cannot fly, other characteristics have the characteristics of “birds”. Therefore, when declaring the “ostrich” class, you can still inherit the “bird”…

In PHP, the difference between 0 and null

In PHP, the difference between 0 and null I don’t know that when you store fields with default data of 0 in the MySQL database, but there is an error when judging 0 or Null in the program, because 0 and Null are not Completely equal, it seems to be a simple problem, but it is very tricky to judge. The values ​​​​of Null and 0 are the same, but the types are not the same. To put it simply, it is the difference between == and ===. The first == only needs the same value, but === not only requires the same value but also the same type of value. Null is a special type. There are two types of Null, such as the following code: 1. $var = NULL; 2. $ var; 3.0, “0”, NULL, and objects without any attributes will be considered empty. Look at the example below Operating results ‘Equal’ ‘Equal’ ‘Not equal’ ‘Equal’ So, the values ​​​​of 0 and Null are equal, but Their types are not equal. Okay, let’s briefly summarize the difference between PHP 0 and null. In short, if you are not clear about the difference, just make a few more judgments.

In php, after a header() jumps to another page, exit() must be added

In php, after a header() jumps to another page, exit() must be added If header() jumps away without adding exit();, the following write statement will be executed (even though it jumps to another page, the following statements will still be executed) ). More related to adding exit() after a header() in PHP jumps to another page Please pay attention to the PHP Chinese website for articles!

In PHP, what is the difference between cookies and sessions, and what are the benefits of using them? (Please give me the answer, not Baidu, thank you)?

Reply content: Let’s not talk about session and COOKIE in Php. Let’s take a look at what session and COOKIE are in the normal web. COOKIE is actually a technology on the browser side. Since HTTP itself is stateless, generally speaking, the server does not know who is requesting each time. Therefore, a web session allows temporary storage of some content on the client through set-COOKIE in the HTTP header. The client needs Each HTTP request in this session is accompanied by the content of the current COOKIE (it will not be sent if COOKIE is disabled). Sessions here are generally defined by domain names. But COOKIE has two big flaws: 1. COOKIE is stored on the client, so COOKIE can be read, appropriated and modified. This means that if any key information, such as login information, is stored using COOKIE, others can read, delete, and modify it at will. 2. Other disguised sites may be able to directly obtain your COOKIE content. So how to access this information to make it difficult for the client to delete COOKIE at will to disguise other users? Generally speaking, there are two major types of methods: 1. Encrypt the COOKIE; 2. Only…

In PHP, we use a large number of numbers to identify types or states. What is the best solution?

Now we use an ftype field int type in the database table in MySQL to identify the type. At this time, there are about 20 types. Because of their age, the various numbers in the program look very laborious. How do you deal with this kind of problem in your program? Now our thinking is: Restrict programmers to use numbers to add labels privately, add a class such as: class action { const EDIT = 0; const VIEW = 1; //… } You must use the parameter action type to use it 2. Use the open source enumeration class on github to implementsuch as: https://github.com/myclabs/ph…

In php, traverse the array to find whether the array element exists and the current string. If it does not exist, output the current string. If it exists, output the key value of the array.

‘Rule buffer clear’, ‘Starting replication’=>’Starting Rule’, ‘Wait -> Brk’=>’Mirror status changes from waiting to stopped status’, ‘OK -> Wait’=>’Mirror status changes from OK to waiting status’, ); $logs = sd_get_log_sys_by_uuid(uuid); for($i=0; $i $v) { $pos = strpos($logs[$i], $k); if($pos !== false){ echo $v; break; } } } } ?> What I want to do is to traverse the array to find whether the array element exists and the current string. If it does not exist, output the current string. If it exists, output the key value of the array. It is the translation function. 1. Determine whether the log has corresponding Chinese characters in the array (because some logs are dead).2. Determine whether some strings in the log have corresponding Chinese characters (some logs contain statements of variables, so it is necessary Use partial string matching and then translate).3. Because there is a loop statement of logs array in the outer layer, use break instead of exit. Reply content: ‘Rule buffer clear’, ‘Starting replication’=>’Starting Rule’, ‘Wait -> Brk’=>’Mirror status changes from waiting to stopping status’, ‘OK -> Wait’=>’Mirror status changes from OK to waiting status’, ); $logs = sd_get_log_sys_by_uuid(uuid); for($i=0; $i $v) { $pos = strpos($logs[$i], $k); if($pos !== false){…

In PHP, there is no instantiation of objects and direct calling of function. What is it called? It’s been a long time since I forgot about it.

In PHP, there is no instantiation of objects and direct call to function. What is it called? What is the syntax? It’s been a long time since I forgot about it. It means that there must be a function in the class, which can be called directly from the outside without instantiating the class, I used to come here, but I haven’t used it for a long time and forgot about it. Sorry for the trouble. Thanks!!! Reply content: In PHP, there is no instantiation of objects and direct call to function. What is it called? What is the syntax? It’s been a long time since I forgot it. It means that there must be a function in the class, which can be called directly from the outside without instantiating the class, I used to come here, but I haven’t used it for a long time and forgot about it. Sorry for the trouble. Thanks!!! The public static function in the class can be called through the :: symbol CLASS::METHOD() static method This is called a static method

In php, get the number of days of the month for a specified date

At work, I often encounter the problem of getting the number of days in a certain month. This is how I solved it before. //Here is November 2015 as an example$inputs[‘month’] = ‘201511’;//Parameters passed$tmp_month = $inputs[‘month’].”01″; //$tmp_mOnth= ‘20151101’;$s_time = strtotime($tmp_month);//Month starting time span>$e_time = strtotime(date(“Ymd”,$s_time).’+ 1 month’);//Month end time$countMins = ($e_time – $s_time)/60;//The number of minutes in the month$countDay = $countMins/(60*24);//The number of days in the month But now, a better way to get it has been discovered . php has a built-in function date() that can directly obtain the number of days in the current month. $tmp_month = $inputs[‘month’].”01″; $countDay = date(“t”,strtotime($tmp_month)); //If you directly date(“t”), you will get the number of days in the current month So easy! In fact, there is another method, using the cal_days_in_month() function. The explanation given in the PHP manual is: return the number of days in a certain month in a certain year in a certain calendar. 3 parameters: calendar A calendar used for calculations month A month in the selected calendar year selects a year in the calendar $num = cal_days_in_month(CAL_GREGORIAN, 11, 2015); // 30 I personally prefer the date() function, so that I don’t have to consider calendar issues. ‘).addClass(‘pre-numbering’).hide();…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索