Private Library Video Learning notes-small fresh BBS system development Technology Induction

Source: Internet
Author: User

I have been learning PHP development, a period of time in the 51cto to see the private library Sun Shenli Teacher's video, downloaded his small fresh BBS system development video learning. Now collect the good use of the inside here.

After looking at this video, you should understand the whole Web project development process.

Public configuration parameters:

<?php
Date_default_timezone_set (' Asia/shanghai ');//Set time zone
Session_Start ();
Header (' Content-type:text/html;charset=utf-8 ');
if (Version_compare (php_version, ' 5.4.0 ') <0) {
Exit (' Your PHP version is '. Php_version. ', our program requirements are PHP version no less than 5.4.0! ');
}
Define (' db_host ', ' localhost ');
Define (' Db_user ', ' root ');
Define (' Db_password ', ' 2015 ');
Define (' Db_database ', ' Sfkbbs ');
Define (' Db_port ', 3306);
Our project (program), the absolute path on the server
Define (' Sa_path ', DirName (dirname (__file__)));
The location of our project under the Web root directory (which directory inside)
Define (' Sub_url ', str_replace ($_server[' document_root '), ', str_replace (' \ \ ', '/', Sa_path)). ' /‘);
if (!file_exists (Sa_path. ') /inc/install.lock ')) {
Header (' Location: '. Sub_url. ' Install.php ');
}
?>

Mysqli common libraries for operational databases:

<?php
Database connection
Function Connect ($host =db_host, $user =db_user, $password =db_password, $database =db_database, $port =db_port) {
[Email Protected]_connect ($host, $user, $password, $database, $port);
if (Mysqli_connect_errno ()) {
Exit (Mysqli_connect_error ());
}
Mysqli_set_charset ($link, ' UTF8 ');
return $link;
}
Executes an SQL statement that returns a result set object or returns a Boolean value
function Execute ($link, $query) {
$result =mysqli_query ($link, $query);
if (Mysqli_errno ($link)) {
Exit (Mysqli_error ($link));
}
return $result;
}
Executes an SQL statement and returns only a Boolean value
function Execute_bool ($link, $query) {
$bool =mysqli_real_query ($link, $query);
if (Mysqli_errno ($link)) {
Exit (Mysqli_error ($link));
}
return $bool;
}
Execute multiple SQL statements at once
/*
Execute multiple SQL statements at once
$link: Connect
$arr _SQLS: Multiple SQL statements in array form
$error: Pass in a variable that stores the error message executed by the statement
Use case:
$arr _sqls=array (
' SELECT * from Sfk_father_module ',
' SELECT * from Sfk_father_module ',
' SELECT * from Sfk_father_module ',
' SELECT * from Sfk_father_module '
);
Var_dump (Execute_multi ($link, $arr _sqls, $error));
Echo $error;
*/
function Execute_multi ($link, $arr _sqls,& $error) {
$sqls =implode ('; ', $arr _sqls). '; ';
if (Mysqli_multi_query ($link, $sqls)) {
$data =array ();
$i =0;//Count
do {
if ($result =mysqli_store_result ($link)) {
$data [$i]=mysqli_fetch_all ($result);
Mysqli_free_result ($result);
}else{
$data [$i]=null;
}
$i + +;
if (!mysqli_more_results ($link)) break;
}while (Mysqli_next_result ($link));
if ($i ==count ($arr _sqls)) {
return $data;
}else{
$error = "SQL statement execution failed: <br/>&nbsp; array subscript {$i} statement: {$arr _sqls[$i]} execution error <br/>&nbsp; error Reason:". mysqli_ Error ($link);
return false;
}
}else{
$error = ' execution failed! Please check that the first statement is correct! <br/> Possible cause of error: '. Mysqli_error ($link);
return false;
}
}
Get Record Count
function num ($link, $sql _count) {
$result =execute ($link, $sql _count);
$count =mysqli_fetch_row ($result);
return $count [0];
}
Data is escaped prior to storage, ensuring that the data can be successfully put into storage
function Escape ($link, $data) {
if (is_string ($data)) {
Return mysqli_real_escape_string ($link, $data);
}
if (Is_array ($data)) {
foreach ($data as $key = = $val) {
$data [$key]=escape ($link, $val);
}
}
return $data;
Mysqli_real_escape_string ($link, $data);
}


To close a connection to a database
function Close ($link) {
Mysqli_close ($link);
}
?>

This article is from the "Lone Boat Night House" blog, please be sure to keep this source http://cysky.blog.51cto.com/211942/1704657

Private Library Video Learning notes-small fresh BBS system development Technology induction

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.