<?php
preg_match( “/c.*?.*?.*?z/”, “phpcodez.com”, $result );
if(count($result))
print_r($result);
?>
Category Archives: PHP
create doc file php
<?php
header(“Content-type: application/vnd.ms-word”);
header(“Content-Disposition: attachment;Filename=test.doc”);
echo “phpcodez”;
?>
SQL LEN()
SQL LEN() returns the length of the value in a text field.
Syntaxt
SELECT LEN(column_name) FROM table_name
SQL FULL JOIN
SQL FULL JOIN return rows when there is a match in one of the tables
Syntax
SELECT * FROM table_name1 FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
MySQL Table – users
|+—-+——+
| id | name |
+—-+——+
| 1 | AAAA |
| 2 | BBBB |
| 3 | CCCC |
| 4 | DDDD |
| 5 | EEEE |
+—-+——+
MySQL Table – Orders
+—–+—–+——–+
| oid | uid | items |
+—–+—–+——–+
| 1 | 1 | Pen |
| 2 | 2 | Watch |
| 3 | 3 | shoe |
| 4 | 4 | mobile |
+—–+—–+——–+
Example
mysql> SELECT u.name,o.items FROM users as u FULL JOIN orders as o ON u.id=o.uid ;
+——+——–+
| name | items |
+——+——–+
| AAAA | Pen |
| BBBB | Watch |
| CCCC | shoe |
| DDDD | mobile |
+——+——–+
4 rows in set (0.00 sec)
SQL SELECT
The SELECT statement is used to select data from a database.
SQL SELECT Syntax
SELECT field_names FROM table_name
Field name should be seperated with comma .
If you want the data from all the fields ,then just use “ * “
MySQL Table – users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | JS |
| 3 | HTML |
| 4 | JSP |
| 5 | ASP |
+—-+——+
Example
mysql> select * from users;
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | PHP |
| 3 | PHP |
| 4 | PHP |
| 5 | PHP |
+—-+——+
mysql> select name from users;
+——+
| name |
+——+
| PHP |
| JS |
| HTML |
| JSP |
| ASP |
+——+
MySQL
MySQL is a relational database management system (RDBMS)that runs as a server providing multi-user access to a number of databases. It is named after co-founder Michael Widenius’ daughter, My. The SQL phrase stands for Structured Query Language.
The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL was owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation.
Free-software-open source projects that require a full-featured database management system often use MySQL. For commercial use, several paid editions are available, and offer additional functionality.
setrawcookie()
It sends an HTTP cookie without URL encoding the cookie value
Example
<?php
setrawcookie(“time”,time());
echo $_COOKIE[‘time’];
?>
Output
1337938950
setcookie()
It sends an HTTP cookie to a client
Example
<?php
setcookie(“time”,time());
echo $_COOKIE[‘time’];
?>
Output
1337938449
headers_sent()
It checks whether headers have been sent .
Example
<?php
if (!headers_sent()) {
header(“Location: http://www.phpcodez.com/”);
exit;
}
?>
headers_list()
It returns a list of response headers sent
Example
<?php
setcookie(“time”,time());
header(‘Content-type: text/plain’);
echo “<pre>”;
print_r(headers_list());
?>
Output
<pre>Array
(
[0] => X-Powered-By: PHP/5.3.3-1ubuntu9.10
[1] => Set-Cookie: time=1337938449
[2] => Content-type: text/plain
)