One Day summary PHP link mysql package database

Source: Internet
Author: User

1: Defining Constants

Define ("HOST", "127.0.0.1");

Define ("USER", "rooot"); Database User

Define ("PWD", "root"); Password

$conn = "";

function Get_coon () {

Global $conn;

$conn = mysql_connect (host,user,pwd) or Die (Mysql_error ());

mysql_select_db ($db, $conn);

mysql_query ("Set names ' UTF8 '");

}

function query ($sql) {

$result = mysql_query ($sql);

$r = Array (); declares an empty array

while ($row = Mysql_fetch_array ($result)) {

$r [] = $row;

without a loop , pass the $row to $rso that$r An automatically numbered two-dimensional array

}

Return $r;

}

Insert Method

function Insert ($sql) {

$result = mysql_query ($sql);

return $result;

}

function Close () {

Global%conn;

Mysql_close ($conn);

}

2: Call

<?php

Include ("dbhelper.php");

Get_conn ();

$r = Query ("Select *from users");

foreach ($r as $row) {

?>

<?php

}

?>

(2):Function Text1 ($str 1, $str 2) {

to split an array into strings

The following method means that$str 2 should be an array

and then divide the array into a new string, as well.

$SL = Implode (".". $str 2);

Echo "$SL";

splitting a string into an array explode

This function means that first $str 1 is a string that is assembled according to a specification.

This specification is a style that must conform to the first parameter above

$tr 2 = Explode ("-", $str 1);

Print_r ($s 2);

}

(3):Substr

(4):vsprintf ("%d-%d-%d", array );

gets an array of all arguments passed in

Cases:

$arr = [A]

Echo vsprintf ("%d-%d-%d", $arr);

(5):%d(array type) equals placeholder

%s(character type)

//

Func_num_args ();

get function All parameters

Func_get_args ();

(6):str_replace ("", "", ");

(7) Str_replace ();

(8) Array_shift ();

(9) Var_dump ();

Related Article

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.