In php, how to export the database table to json/word/xml/excel_PHP tutorial
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: The following is a 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 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: The following is a code snippet: $db=new db(); echo $db->toExtJson('test'); //The output result is //{'totalCount':'2','rows':[{'id':'1&# 39;,'name':'pjq518','email':'[email protected]','age' ;:'22'},{'id':'2','name':'xiaoyu',& #39;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: The following is a code snippet: $db=new db(); echo $db->toExtXml('test'); //Output results 3. Export excel and word PHP code: The following is a code snippet: $db=new db(); //toExcel $map=array('No','Name','Email','Age');//Header $db->toExcel('test', $map,'File'); //Export word table // $db->toWord('test', $map,'File'); //The effect is as shown below PHP code: <?php…
In PHP, why does </script> not generate a syntax parsing error_PHP Tutorial
As a mainstream website construction language, PHP has many pitfalls during use, which requires programmers to think. In PHP script, if you write the following code <?php ?> This php script did not prompt any errors, but directly output “?>”. It feels incredible, so we write the following code <?php ?> This time it prompts a parsing error, Parse error: syntax error, unexpected '<' in … Why is there no error message 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: You can use four different pairs of opening and closing tags 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 tags, abandoned in version 5.3.0) http://www.bkjia.com/PHPjc/477852.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477852.htmlTechArticlePHP, as a mainstream website construction language, has many pitfalls during its use, which requires programmers’ ideas. In a PHP script, if you…
In PHP::, ->, self, $this operator_PHP tutorial-php tutorial
When accessing member variables or methods in a PHP class, if the referenced variable or method is declared as const (defining a constant) or static (declaring static), then you must use the operator::, otherwise if the referenced variable or method If the method is not declared const or static, the operator -> must be used. In addition, if you access a const or static variable or method from within the class, you must use self-reference. On the contrary, if you access a non-const or static variable or method from within the class, you must use self-reference. $this. $this instance The code is as follows <?php //this is a pointer to the current object class test_this{ private $content; //Define variables function __construct($content){ //Define constructor $this->cOntent= $content; } function __destruct(){}//Define destructor function printContent(){//Define printing function echo $this->content.’‘; } } $test=new test_this(‘Welcome to Beijing!’); //Instantiated object $test->printContent();//Welcome to Beijing! ::Usage The code is as follows //parent is a pointer to the parent class class test_parent{ //base class public $name; //Define name. Parent class members need to be defined as public before they can be called directly using this in the inherited class. function __construct($name){ $this->name=$name; } } class test_son extends test_parent{ // Derived…
In php, strtotime gives a time and returns the Monday where the time is_PHP Tutorial
A simple implementation code of strtotime in PHP returns the Monday where the time is located for a given time. Friends in need can refer to it. The strtotime() function parses any English text datetime description into a Unix timestamp. Very simple: The code is as follows echo strtotime(‘-1 Mon’,strtotime(“2010-01-01”));//Return the Monday of the date and time echo strtotime(‘Mon’,strtotime(“2010-01-01”));//Returns the time on the next Monday after the date and time http://www.bkjia.com/PHPjc/628896.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/628896.htmlTechArticleA simple implementation code for strtotime in PHP to return the Monday where the time is based on a time. Friends in need can refer to it. The strtotime() function decodes the date and time description of any English text…
In PHP, you can use arrays to generate sql statements to be executed charmingly, array sql_PHP tutorial
In PHP, arrays are used to generate sql statements to be executed. Array sql Will you encounter such a situation? Each time the data is obtained, there will be a certain difference between the data and the historical version. However, using ThinkPHP’s addAll() function, the existing data will be deleted and rewritten. This is obviously not what we want. But writing sql by myself with dozens of fields every time is also boring. How to achieve automatic generation of sql elegantly and easily? So here is the method below. /** * [array_to_sql is spliced into the required sql based on the array key and value] * @param [type] $array [key, value structure array] * @param string $type [sql type insert, update] * @param array $exclude [excluded fields] * @return [string] [Return the spliced sql] */ function array_to_sql($array, $type=’insert’, $exclude = array()){ $sql = ”; if(count($array) > 0){ foreach ($exclude as $exkey) { unset($array[$exkey]);//Eliminate unnecessary keys } if(‘insert’ == $type){ $keys = array_keys($array); $values = array_values($array); $col = implode(“`, `”, $keys); $val = implode(“‘, ‘”, $values); $sql = “(`$col`) values(‘$val’)”; }else if(‘update’ == $type){ $tempsql = ”; $temparr = array(); foreach ($array as $key => $value) { $tempsql = “‘$key’ =…
In php, enter an address to display the content of another website, and the address should be the address I just entered. Wait online.
In php environment I want to enter www.xy.com to directly display the website content of the other party (www.a.com/key/a), and the displayed address is the www.xy I just entered. .com How to achieve this? Do I need to modify the configuration file? thanks. Reply to discussion (solution) Just use a frame URL rewriting operation requires changing the server configuration file Use the iframe tag of html http ://www.w3school.com.cn/tags/tag_iframe.asp ————————— —————————-AutoCSDN signature file——————– ———————————- Code farm? Code farmers sow code and herd thoughts farm! Use the curl function This is not about PHP, it is about the server software. You can use rewrite in apache. Or use html iframe Write on the html page of www.xy.com:
In php, what is the problem when using echo to call JS function? -php tutorial
<?php echo “”; ?> js function: function show_p(){ document.getElementById(“show”). style.display=”block”; } //p is hidden, I want to display p by calling JS function through php Reply to discussion (solution) Of course there is no problem in calling. What you need to pay attention to is that the code of the js function must be output before echo. And your id= The p in show should be output before the js code p->js ->php echo jscode. php-> Is it possible to implement the sequence p->js? If I put php at the end, it will affect other functions… When php outputs and calls js, neither p nor js code exists. How can it be executed? This does not mean that you type it directly on the page What do you think it will do? Why do I use echo ” “; p can be displayed? It doesn’t work when using echo “”; directly. What’s the difference between them? Page execution is from top to bottom. . You just put the p and js functions on the PHP page. setTimeout(‘show_p()’,10) It means calling the show_p() function after 10 milliseconds. At this time, the DOM will naturally be loaded. Sorry, typo. You just put…
In php, how to use MSClass (ClassOfMarqueeScroll universal uninterrupted scrolling JS encapsulation class)
Ask an expert, I want to make scrolling effect, how to use MSClass (Class Of Marquee Scroll universal uninterrupted scrolling JS encapsulation class) in php I saw it online (http://www.popub.net/script/MSClass .html) are provided by asp. Now I want to read the image data from the database. What should I do? Reply to the discussion ( Solution) I wrote one myself, but it ran wrong $sql=”select f_images from user_info_input limit 30″; $result=mysql_query($ sql); while($row=mysql_fetch_array($result)){ echo “ “; echo “ “; echo ““; echo “ “; echo “ “; Previous page Next page Tool for running php online http://www.coderun.com/ide/ Waiting, please give some advice Just check it on Baidu
In php, how to pass two parameters through soap (under ms-security)
$xml = ‘ admin PasswordText ‘; $header = new SoapHeader(‘http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd’, ‘CallbackHandler’, new SoapVar($ xml, (‘checkUser’, array(‘username’ => array(‘username’ => ‘username’, ‘password’ => ‘password’)))); As soon as the above code is run, an error is prompted SoapFault exception: [soap:Server] Fault occurred while processing. in Later, during the continuous adjustment, the other party looked at the log and it showed that the username was passed but the password was not passed When a parameter is passed, the other party can receive it /> $info = turnObjectToArray($this->client->__call(‘getClasses’, array(‘gradeId’ => array(‘gradeId’ => $data[ ‘id’])))); How to pass two parameters? ? ? Reply to discussion (solution) Pay attention to capitalization! What is the case, method or parameter? The moderator’s answer inspired me, and I saw the parameters to be passed in wsdl. , the parameter the other party mentioned in q was password, but in wsdl it was indeed pwd, I was so angry
In PHP, using PDO method, calling the stored procedure fails.
MYSQL, stored procedure CREATE DEFINER=`trip_admin`@`localhost` PROCEDURE `outtemp`(OUT `p_outtext` VARCHAR(100))proc:BEGIN set p_outtext =’Test’; insert into temp (tp) value (p_outtext);END The table TEMP has only one tp field. Using PHP and PDO to call this stored procedure, there is no return value and no data is added to the table. $DSN = “$DBMS:host=$HOST;dbname=$DBName”; $pdo = new PDO($DSN,$UserName,$PassWord) ; $pdo -> query(“set names uft8”); $result=$pdo->prepare(“call outtemp (?)”); $result->bindParam(1,$result_text,PDO::PARAM_STR,100) ; $result->execute(); Environment: windows server 2008 x64 MySQL 5.6.19 PHP 5.5.14 Reply to discussion (solution) Research and find out what happened. It also solves the problem of how to call a stored procedure with multiple IN and OUT parameters and obtain the return value using PDO.